如何在运行时在 FrameLayout 中更改 ImageView 大小
How to change the ImageView size at runtime within FrameLayout
我在 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的实例。
您需要重新分配 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();