在我的应用程序中,我动态添加单选按钮,成功我可以添加并获取值我的问题是UI,它未正确对齐,布局权重dint在我的UI中进行任何更改
检查我的编码
具有文本视图和Radion按钮
LinearLayout.LayoutParams mainparams = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
mainparams.setMargins(0, 8, 0, 0);
我的动态文字视图
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输出
我的单选按钮需要像edittext一样对齐,请帮助我找到合适的解决方案,
提前致谢,
答案 0 :(得分:1)
//您还需要将布局参数设置为Radio组
同样mainparams1
您也可以重复使用RadioGroup
LinearLayout.LayoutParams mainparams1 = new LinearLayout.LayoutParams(
0, LayoutParams.WRAP_CONTENT);
rg.setLayoutParams(mainparams1);
答案 1 :(得分:0)
您尚未指定Weightsum
li.setWeightSum(weightSum);
其中weightSum =所有子视图的总权重