Android的线性布局重编程方式 [英] Android Linear Layout Weight Programatically

查看:132
本文介绍了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 programatically. 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;

请参阅完整的解决方案。

See Full Solution

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的线性布局重编程方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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