本文介绍了Android线性布局权重以编程方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想以编程方式向活动添加三个线性布局,每个线性布局均具有相同的宽度.问题是我无法以编程方式设置这些布局的权重.我可以在xml中执行此操作,但是我想在程序中执行此操作.这是我想要的:
I want to add three linear layouts to an activity programatically each of same width. the problem is i am not able to set the weights of these layouts programmatically. I could do this within xml, but I want to do this in program.here is what I want:
推荐答案
以下是解决方案
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0, 100);
lp.weight = 1;
查看完整解决方案
LinearLayout ll1, ll2, ll3;
/* Find these LinearLayout by ID
i.e ll1=(LinearLayout)findViewById(R.id.ll1);
*/
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0, 100);
lp.weight = 1;
ll1.setLayoutParams(lp);
ll2.setLayoutParams(lp);
ll3.setLayoutParams(lp);
这篇关于Android线性布局权重以编程方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!