在android中改变imageview的高度和宽度

yuv*_*a ツ 6 height layout android width imageview

在我的应用程序按钮单击我想改变imageview的大小.当我点击一个按钮我想增加5的视图尺寸(每个宽度和高度).点击其他按钮我想减小尺寸.i试过这个.我怎么能这样做?下面是code.its无法正常工作

 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);


}
Run Code Online (Sandbox Code Playgroud)

Nic*_*aus 5

更新:

做这个:

int height=imageView.getHeight();
int width=imageView.getWidth();
imageView.setLayoutParams(new LinearLayout.LayoutParams(height, width));
Run Code Online (Sandbox Code Playgroud)


建议您的ImageView位于LinearLayout内,您需要这样做:

LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) imageView.getLayoutParams();
params.setHeight(XX);
params.setWidth(XX);
imageView.setLayoutParams(params);
Run Code Online (Sandbox Code Playgroud)

我不知道语法是否完全正确,但基本上就是这样做,不要忘记你需要更新你的UI,以便看到任何变化.