2011-07-15 16 views
0

私はAndroid開発の初心者ですので、過去2〜3ヶ月の間に物事を取り上げています。画像をオーバーレイするのに最適な方法は何ですか?

私が書いているアプリでは、2つの画像を表示する必要があります。上の画像には、下の画像を表示する透明な領域がいくつかあります。

問題は、これを行う正しい方法がわからないことです。これは動作しますが、私は以来、同じことは、関連付けられたビューの上に配置ImageViewのを使用して達成することができるかについて読んだことがある

// 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); 
    } 

私は元々書いたコードは次のようになりますメインのアクティビティのレイアウトの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> 

私の質問は本当に正しい方法ですか? 1つは他よりも速いのですか?

どのような考えにも感謝します。

:-)

多くのおかげで、 ウェイン。

答えて

1

私はどちらもそうであると思います。どちらを選択するかは、実際のユースケースによって異なります。ピクセル完全配置が必要ですか?実行時にかなり頻繁に画像を再描画/変更する必要がありますか?キャンバスを使用します。それ以外の場合、FrameLayoutはより汎用性があり、わずか2つの画像を描画するためのカスタムコードは必要ありません。

私はスピードワイドではわかりませんが、私は測定し、あなたが得るものを見ています。このチュートリアルhereを参照してください。もしあなたがAndroidを初めてお使いの場合は、これをお読みください。一般的に知っておくと便利です。

+0

よろしくお願いします。私がやったことが正しいことを何らかの安心感を得てうれしいです。 – Wayne

関連する問題