在我的应用程序中,单击按钮时我想更改 imageview 的大小。当我单击一个按钮时,我想将 imageview 的大小增加 5(每个宽度和高度)。单击其他按钮时,我想减小尺寸。我试过了。 我该怎么做?下面是代码。它不起作用
public void increase(View v)
{
int height=imageView.getHeight();
int width=imageView.getWidth();
imageView.getLayoutParams().height = height+5;
int h=imageView.getHeight();
System.out.println("hhhhhhhhhh,,,,,,,,,,"+h);
System.out.println("width n hight..."+width+"and"+height);
}
最佳答案
更新:
这样做:
int height=imageView.getHeight();
int width=imageView.getWidth();
imageView.setLayoutParams(new LinearLayout.LayoutParams(height, width));
建议您的 ImageView 位于 LinearLayout 内,您需要这样做:
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) imageView.getLayoutParams();
params.setHeight(XX);
params.setWidth(XX);
imageView.setLayoutParams(params);
我不知道语法是否完全正确,但基本上这就是你的做法,不要忘记你需要更新你的用户界面,以便看到任何变化。
关于android - 在android中更改imageview的高度和宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15070866/