我在FrameLayout中有一个ImageView。我以编程方式增加FrameLayout的大小,但ImageView大小没有变化。我已将ImageView paramas设置为MatchParent。请帮我看看如何在frameLayout中增加图像的大小?
这里我已将图像添加到FrameLayout中:
img_pinch=new ImageView(getApplication());
img_pinch.setImageBitmap(m_bitmap);
img_pinch.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
FrameLayout fm=new FrameLayout(getApplication());
FrameLayout.LayoutParams params=new FrameLayout.LayoutParams(400,300);
fm.addView(img_pinch,params);
下面是更改frameLayout大小的代码:
int x = (int) temp_img_logo.getWidth();
int y = (int) temp_img_logo.getHeight();
temp_img_logo.setLayoutParams(new android.widget.AbsoluteLayout.LayoutParams(x+5,y+5,(int)temp_img_logo.getX(),(int)temp_img_logo.getY()));
temp_img_logo.invalidate();
temp_img_logo是FrameLayout的实例。
答案 0 :(得分:0)
您需要重新分配imageview以相应地增加尺寸,试试这个,
刚开始时,
img_pinch=new ImageView(getApplication());
img_pinch.setImageBitmap(m_bitmap);
img_pinch.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
FrameLayout fm=new FrameLayout(getApplication());
FrameLayout.LayoutParams params=new FrameLayout.LayoutParams(400,300);
fm.addView(img_pinch,params);
当您需要增加框架布局的大小时,
temp_img_logo .removeAllViews();
temp_img_logo .setLayoutParams(new LayoutParams(400, 400)); // 400 will be use as example
img_pinch.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
temp_img_logo .addView(img_pinch);
temp_img_logo .invalidate();