在我的应用程序中,我已动态添加单选按钮,成功我可以添加并获取值我的问题是UI,它未正确对齐,布局权重dint在我的UI中进行任何更改

看看我的编码

有文本视图和Radion按钮

LinearLayout.LayoutParams mainparams = new LinearLayout.LayoutParams(
                        LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
                mainparams.setMargins(0, 8, 0, 0);

我的动态Textview

    LinearLayout li = new LinearLayout(Appointmentdetails.this);
    li.setOrientation(LinearLayout.HORIZONTAL);

    li.setLayoutParams(mainparams);

    LinearLayout.LayoutParams mainparams1 = new LinearLayout.LayoutParams(
            0, LayoutParams.WRAP_CONTENT);
    mainparams1.setMargins(0, 10, 0, 0);

    mainparams1.weight = 1f;
    TextView tv = new TextView(this);
    tv.setTextSize(18);
    tv.setTypeface(Typeface.DEFAULT_BOLD);
    tv.setTypeface(MyriadPro);
    tv.setLayoutParams(mainparams1);
    tv.setText(Alldata.question.get(i).getgQuestion());
    tv.setSingleLine();
    tv.setPadding(25, 10, 0, 0);
    tv.setTextColor(Color.parseColor("#009099"));
    tv.setMarqueeRepeatLimit(10);
    tv.setEllipsize(TruncateAt.MARQUEE);
    tv.setSelected(true);

我的动态单选按钮

RadioGroup rg = new RadioGroup(Appointmentdetails.this);

                // rg.setLayoutParams(lparams1);

                gAnswerList.add("Select vlaue");
                for (int j = 0; j < helptext.split(Expressions).length; j++) {
                    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                            LayoutParams.WRAP_CONTENT,
                            LayoutParams.WRAP_CONTENT);

                    params.setMargins(5, 0, 0, 0);
                    // Edittext.setLayoutParams(lparams1);
                    params.weight = 1.6f;
                    RadioButton rb = new RadioButton(Appointmentdetails.this);
                    rb.setText(helptext.split(Expressions)[j].toString());
                    rb.setId(j);
                    rb.setLayoutParams(params);
                    rg.addView(rb);

                }


                li.addView(tv);
                li.addView(rg);
                mQuestionLayout.addView(li);

我的Curent输出 在此输入图像描述

我的单选按钮需要像编辑文本一样对齐,请帮助我获得正确的解决方案,

提前致谢,

===============>>#1 票数:1 已采纳

//你还需要将布局参数设置为Radio组

相同的mainparams1也可以重复用于RadioGroup

 LinearLayout.LayoutParams mainparams1 = new LinearLayout.LayoutParams(
            0, LayoutParams.WRAP_CONTENT);

rg.setLayoutParams(mainparams1);

===============>>#2 票数:0

你还没有指定Weightsum

    li.setWeightSum(weightSum);

其中weightSum =所有子视图的总权重

  ask by Madhu translate from so

未解决问题?本站智能推荐: