线性布局添加视图不会达到全宽

时间:2017-08-17 06:14:59

标签: android layout android-linearlayout

LinearLayout RadioGroup RadioGroupaddview() LinearLayout radiogroup_ans.setOrientation(LinearLayout.VERTICAL); radiogroup_ans.removeAllViews(); radiogroup_ans.clearCheck(); for (int i = 0; i < subjectDetailMain.getSubjectdetail().get(0).getPackageDetailArrayList().size(); i++) { LinearLayout lnr=new LinearLayout(this); RadioButton rb_answer = new RadioButton(this); LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(RadioGroup.LayoutParams.WRAP_CONTENT, RadioGroup.LayoutParams.WRAP_CONTENT); rb_answer.setLayoutParams(p); rb_answer.setId(i); rb_answer.setTag(i); LayoutInflater vi = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); View v = vi.inflate(R.layout.packagelist_layout,(ViewGroup) null); p = new LinearLayout.LayoutParams(RadioGroup.LayoutParams.MATCH_PARENT, RadioGroup.LayoutParams.WRAP_CONTENT,1.0f); v.setLayoutParams(p); lnr.addView(rb_answer); lnr.addView(v); radiogroup_ans.addView(lnr); } let add x y = x + y let n = add 2 3 // Now n has the value 5 let addFive = add 5 // This is a *function* that takes one parameter let altAddFive y = add 5 y // Another way to define the same thing let result = addFive 3 // Now result has the value 8 let altResult = altAddFive 3 // This one also has the value 8 我可以添加视图但我的视图没有达到全宽。

这是我的代码

score

这里的输出是它的外观

image

这是我想要的图像

image2

2 个答案:

答案 0 :(得分:0)

LinearLayout lnr=new LinearLayout(this);
LayoutParams LParams = new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT);
lnr.setLayoutParams(LParams);

将布局参数设置为lnr

答案 1 :(得分:0)

使用此代码。我希望它会有所帮助

 var options = {
        setStatic: true,
    };
    $('.grid-stack').gridstack(options);