View
メソッドをオーバーライドしonDraw
てかなり複雑な UI を描画するカスタム オブジェクトを作成しました。これらのカスタム ビューを 5 つ LinearLayout に追加していますが、一度に表示できるビューは 1 つだけです。
アプリケーション内のユーザーのアクションに応じて、View.Visibility
それぞれのプロパティを切り替えて、1 つだけが表示されるようにします。
明確にするために、私が使用している方法は私にとってはうまくいき、かなり反応が良いようです。この方法がローエンドまたはロースペックのデバイスにどのように影響するか、少し心配です。
これが私の現在のコードのサンプルです:
カスタム ビュー
public class MyDrawingView extends View {
private Bitmap mViewBitmap;
private int mWidth = 1024; // The width of the device screen
private int mHeight = 600; // Example value, this is dynamic
@Override
protected void onDraw(Canvas canvas) {
// Copy the in-memory bitmap to the canvas.
if(mViewBitmap != null) canvas.drawBitmap(mViewBitmap, 0, 0, mCanvasPaint);
}
private void drawMe() {
if(mViewBitmap == null) mViewBitmap = Bitmap.createBitmap(mWidth, mHeight, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(mViewBitmap);
c.drawBitmap(...);
c.drawText(...);
// Multiple different methods here drawing onto the canvas
c.save();
}
}
レイアウト XML
<LinearLayout>
<com.company.project.ui.MyDrawingView
android:id="@+id/myCustomView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<com.company.project.ui.MyDrawingView
android:id="@+id/myCustomView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<com.company.project.ui.MyDrawingView
android:id="@+id/myCustomView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<com.company.project.ui.MyDrawingView
android:id="@+id/myCustomView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<com.company.project.ui.MyDrawingView
android:id="@+id/myCustomView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
質問
- サイズ 1024x600 のビットマップを使用して、View のこれら 5 つの個別のインスタンスを常にメモリに保持する必要がありますか?
- ビューを更新する必要があるたびにビットマップを再生成し、レイアウト XML に 1 つのビューを追加するだけでよいように、機能をマージする必要がありますか?
- ビットマップの再描画には複雑なため時間がかかる場合があることを念頭に置いて、どのオプションがパフォーマンスに優れていますか?
ドキュメンテーション
Managing Bitmap Memoryに関する Android のドキュメントを既に読みましたが、カスタム ビューで既に概説したポイントを実装したと感じており、それが私のシナリオを完全にカバーしているとは思いません。