android - 在android中更改imageview的高度和宽度

标签 android layout height imageview width

在我的应用程序中,单击按钮时我想更改 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/

相关文章:

java - 使用其他应用程序(插件)更新应用程序信息

java - 使用 GridBagConstraints 的奇怪布局

css - 960网格边界困惑。

delphi - 我可以让 TComboBoxEx 与 TComboBox 具有相同的高度吗?

android - 使用 XMPP (4.1.3) 创建组时获取 "XMPPException$XMPPErrorException: XMPPError: service-unavailable - cancel"

Android 可扩展列表选择器行为

android - 每行具有不同 spanCount 的 RecyclerView

forms - ExtJS - 在 FormPanel 列布局中排列表单元素

html - <p> 标签之间的行高不同

algorithm - Diamond-Square 算法的平滑问题