Android - How can I add an image view dynamically?
I would like to add an image view dynamically and then add a 2 bitmaps to that view, how can I d开发者_如何学运维o this?
I don't think you can add two bitmaps to a single image view: it sounds like you'll need to create two image views to wrap each bitmap and position them how you want the two bitmaps to be relative to each other. Maybe surround the two ImageViews with a RelativeLayout.
Untested Pseudocode:
RelativeLayout layout = new RelativeLayout(this);
// TODO: Set attributes for layout
// i.e. RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
// layout.setLayoutParams(params);
ImageView imageView1 = new ImageView(this);
imageView1.setBackgroundResource(R.drawable.bitmap1);
ImageView imageView2 = new ImageView(this);
imageView2.setBackgroundResource(R.drawable.bitmap2);
// TODO: Set LayoutParams for each imageView
// i.e. RelativeLayout.LayoutParams imageParams1 = new RelativeLayout.LayoutParams(imageWidth, imageHeight);
// imageParams1.addRule(RelativeLayout.ALIGN_PARENT_TOP);
// imageParams1.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
layout.addView(imageView1, imageParams1);
layout.addView(imageView2, imageParams2);
精彩评论