开发者

Android : Canvas.drawBitmap() or Imageview.setImageBitmap(bitmap)

开发者 https://www.devze.com 2023-03-28 12:44 出处:网络
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(...)?

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号