如何在FrameLayout中的运行时更改ImageView大小 [英] How to change the ImageView size at runtime within FrameLayout
问题描述
我在FrameLayout中有一个ImageView。我以编程方式增加FrameLayout的大小,但ImageView大小没有变化。我已将ImageView paramas设置为MatchParent。请帮我看看如何增加frameLayout中图像的大小?
I have one ImageView inside FrameLayout. I am increasing the size of FrameLayout programmatically but ImageView size is not changing. I have set the ImageView paramas as MatchParent. Please Help me how to increase the size of image within frameLayout?
这里我已将图像添加到FrameLayout中:
here I have added the image into 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大小的代码:
below is the code to change the size of 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的实例。
temp_img_logo is the instance of FrameLayout.
推荐答案
您需要重新分配imageview以相应地增加尺寸,试试这个,
You need to re-assign the imageview in order to increase the size accordingly , Try this,
在开始时,
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);
当你需要增加框架布局的大小时,
When you need to increase the size of frame layout ,
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();
这篇关于如何在FrameLayout中的运行时更改ImageView大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!