【发布时间】:2021-10-21 12:08:55
【问题描述】:
我是 android 的新手。需要在 RadioGroup 内动态创建 LinearLayout 并对齐 TextViews,如下所示。在这里,我只是从调色板中移动了元素,并没有更改任何属性
但是得到这个
我错过了什么?
LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT, /* or MATCH_PARENT */
LinearLayout.LayoutParams.WRAP_CONTENT, /* or MATCH_PARENT */
1.0f);
final LinearLayout linearLayout = new LinearLayout(this);
final TextView text1 = new TextView(this);
text1.setText("aaa");
text1.setLayoutParams(param);
linearLayout.addView(text1);
final TextView text2 = new TextView(this);
text2.setText("bbb");
text2.setLayoutParams(param);
linearLayout.addView(text2);
final TextView text3 = new TextView(this);
text3.setText("ccc");
text3.setLayoutParams(param);
linearLayout.addView(text3);
radioGroup.addView(linearLayout);
【问题讨论】:
标签: android dynamic android-linearlayout