我想动态添加图像视图,然后向该视图添加2位图,我该怎么做?
答案 0 :(得分:9)
我认为你不能在单个图像视图中添加两个位图:听起来你需要创建两个图像视图来包装每个位图,并将它们放在两个位图相对于彼此的位置上。也许用RelativeLayout围绕两个ImageView。
未经测试的伪代码:
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);