0
我是Android开发的新手,所以在过去的几个月里一直在挑选事物。什么是最好的/正确的方式来覆盖图像
我正在写的应用程序需要显示两个图像,一个在另一个上面。顶部的图像有一些透明区域,我希望下面的图像出现。
问题是,我不确定什么是正确的方法来做到这一点。
我最初写的代码看起来是这样的:
// background worker thread Run() method
Canvas canvas = null;
try
{
canvas = _surfaceHolder.lockCanvas(null);
synchronized(_surfaceHolder)
{
canvas.drawBitmap(_backgroundBitmap, 0, 0, null);
// ...
canvas.drawBitmap(_foregroundBitmap, 0, 0, null);
}
}
finally
{
if(canvas != null)
_surfaceHolder.unlockCanvasAndPost(canvas);
}
虽然这个工程,因为读我有是怎么一回事可以使用定位在与相关联的视图顶部的ImageView的实现在主要活动布局xml文件中的应用程序:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!-- This is the surface where the application is responsible for drawing to -->
<com.test.MainAppView
android:id="@+id/mainView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
<!--
This is where a foreground graphic could be displayed which allows me
to remove the drawBitmap() code from the Run() method shown above.
-->
<ImageView
android:id="@+id/foregroundgraphic"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</FrameLayout>
所以我的问题是真的哪个是正确的方法?一个比另一个快吗?
任何想法将不胜感激。
:-)
非常感谢, 韦恩。
好的,谢谢你的建议。很高兴得到一些保证,我所做的是正确的。 – Wayne