Suppose I want to create an activity that displays 12 different PNG images.
Should I create a class extending View (let say "MyView") in which I would use 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(...)
}
}
Or should I use 12 ImageView objects and set the bitmap in each one of it?
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);
}
...
}
I think creating an ImageView
will have more overhead.
However, it will provide more easily implemented functions
精彩评论