1
假設我想創建一個顯示12個不同PNG圖像的活動。Android:Canvas.drawBitmap()或Imageview.setImageBitmap(位圖)
我應該創建一個類擴展視圖(讓我說「MyView」)至極我將使用canvas.drawBitmap(...)?
public class MyActivity extends Activity {
private MyView myView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
myView = new MyView(this);
setContentView(myView);
myView.requestFocus();
}
...
}
public class MyView extends View {
@Override
protected void onDraw(Canvas canvas) {
// do that 12 times ...
canvas.drawBitmap(...)
}
}
或者我應該使用12個ImageView對象並在其中的每一箇中設置位圖?
public class MyActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout root = new LinearLayout(this);
// do that 12 time ...
ImageView imageView = new ImageView();
Bitmap bitmap = BitmapFactory.decodeFile(...);
imageView.setImageBitmap(bitmap);
root.addView(imageView);
}
...
}
謝謝。
埃裏克