[英]set the width of the button to the LinearLayout programmatically
I am trying to set the width of the button in the lila
LinearLayout but I am getting it just like in the screenshot. 我正在尝试在
lila
LinearLayout中设置按钮的宽度,但是就像在屏幕截图中一样。 How can I set the width for the button? 如何设置按钮的宽度? I am facing another Problem the item number beside the checkboxes are a Little bit higher than the Level of the Checkbox.
我面临另一个问题,即复选框旁边的项目号比复选框的级别高一点。 How can I configure that programmatically to set them to the same level ?
如何以编程方式配置它们以将它们设置为同一级别?
private void createRadioButton(final ArrayList<Integer> items) {
final LinearLayout ll = (LinearLayout) findViewById(R.id.lila);
for (int i = 0; i < items.size(); i++) {
CheckBox cb = new CheckBox(this);
cb.setText(items.get(i) + "\n");
cb.setId(i + 10);
ll.addView(cb);
}
Button btn = new Button(this);
btn.setText("submit");
// With this line below I am not getting the button displayed.
//btn.setLayoutParams(new LinearLayout.LayoutParams(10, 40));
ll.addView(btn);
}
Screenshot: 截图:
About number displayed higher than checkbox. 关于显示的数字高于复选框。
In your code cb.setText(items.get(i) + "\\n");
在您的代码中
cb.setText(items.get(i) + "\\n");
you are putting new line, so next to checkbox is diplayed number AND new line 您要放置新行,所以复选框旁边是已显示的数字和新行
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.