android - 使用 LinearLayout.LayoutParams 将 WRAP_CONTENT 更改为设定的数字

标签 android android-linearlayout layoutparams

我已经设置了一些 LinearLayout.LayoutParams 以仅使用 java 设置一些按钮。但我想将其从 WRAP_CONTENT 更改为我选择的高度和宽度。

//LinearLayout.LayoutParams top;
//this is declared at the top as it is used by different bits of the code.
top = new LinearLayout.LayoutParams
            (LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    top.topMargin = 100;
    top.leftMargin = 120;

最佳答案

top = new LinearLayout.LayoutParams
            (90, 80); 

//随你喜欢

这是来自文档:

public LayoutParams(int width, int height) {
        super(width, height);
        weight = 0;
    }

关于android - 使用 LinearLayout.LayoutParams 将 WRAP_CONTENT 更改为设定的数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39408567/

相关文章:

android - 当我引用 AppBarLayout 并尝试使用 AppBarLayout.LayoutParams 获取它的 LayoutParams 时,为什么会出现类转换异常?

android - 如何在Android中顺利展开 View ?

android - 如何创建 Json 对象

java - Libgdx 如何使用电话方向在多个轴上旋转 3D 模型

android - 无法从终端启动 Android 应用程序 : java. lang.SecurityException:权限拒绝启动 Intent - 未导出

java - 如何以编程方式设置 imageView 的高度?

android - 将 JSON 转换为游标

android - 创建 ImageView 和 TextView 的 ViewGroup 并以编程方式将其显示在 FlowLayout 中 - Android

android - 如何使应用程序响应所有 Android 设备?

android - Horizo​​ntal LinearLayout 在嵌套 Vertical LinearLayout 后不显示任何元素