Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/207.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何在代码中设置孩子的体重?_Android_Android Widget - Fatal编程技术网

Android 如何在代码中设置孩子的体重?

Android 如何在代码中设置孩子的体重?,android,android-widget,Android,Android Widget,我希望该按钮(子按钮)具有水平线性布局(其父按钮)全宽的25%。守则: LinearLayout ll = new LinearLayout(this); ll.setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT)); ll.setWeightSum (1.0f); Button b = new Button (this); ll.addView(b); 我怎

我希望该按钮(子按钮)具有水平线性布局(其父按钮)全宽的25%。守则:

LinearLayout ll = new LinearLayout(this);
ll.setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
ll.setWeightSum (1.0f);

Button b = new Button (this);
ll.addView(b);
我怎么做?谢谢。

试试这个:

    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENTS,LayoutParams.FILL_PARENT));
    lp.weight = 0.25;
    b.setLayoutParams(lp);

您可以将其作为
LinearLayout.LayoutParams
构造函数的一部分传入:

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

请检查这个:Hi infinity。我想我已经开始了解布局参数了。谢谢。@tatiana_c-如果“无限”的答案对你有效,请确保将答案标记为已接受,以便我们都能受益。嗨,Garry,你的意思是在问题中选择“是”按钮,如果它对我有用吗?我是这个网站的新用户,谢谢。加里,你好。我的问题不再相关了,在我的其他帖子中有人向我解释了。我会的。谢谢