以编程方式设置重量(百分比) [英] Set weight (percentage) programmatically

查看:61
本文介绍了以编程方式设置重量(百分比)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个按钮,我想动态调整权重.它们以.5的权重开始(当然,这会增加LinearLayout的权重1),但是如果首选项为true,那么我想将其权重分别更改为.7和.3.我可以在XML中设置权重,但似乎找不到如何以编程方式更改权重.

I've got two buttons that I'd like to dynamically weight give a preference. They start out each with a weight of .5 (which of course adds to the LinearLayout's weight of 1), but if the preference is true, then I'd like to change their weights to .7 and .3 respectively. I can set the weight in XML but I can't seem to find how to change it programmatically.

解决方案

LinearLayout.LayoutParams PO = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, .60f);
LinearLayout.LayoutParams MO = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, .20f);

推荐答案

查看 LayoutParams ,它具有用于设置重量的字段

Look into LayoutParams, it has a field for setting the weight

这篇关于以编程方式设置重量(百分比)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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