如何动态地从code设置layout_weight属性? [英] How to set layout_weight attribute dynamically from code?

查看:237
本文介绍了如何动态地从code设置layout_weight属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何设置的值动态从Java code在Android上的属性 layout_weight 的按钮?

How can i set the value for the attribute layout_weight for button in android dynamically from java code ?

推荐答案

您可以通过它在作为 LinearLayout.LayoutParams 构造的一部分:

You can pass it in as part of the LinearLayout.LayoutParams constructor:

LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(
                             LayoutParams.MATCH_PARENT,
                             LayoutParams.MATCH_PARENT, 1.0f);

的最后一个参数是重

The last parameter is the weight.

这篇关于如何动态地从code设置layout_weight属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆