我正在开发一个Android应用程序。在我的应用程序中,我将复选框以编程方式添加到LinearLayout。但添加复选框后,它不适合布局。请参阅下面的屏幕截图。以编程方式添加带标题的复选框不适合Android中的布局
截图
正如你在截图 “X-samll” 文本及其复选框看到没有正确安装。我想要的是当没有足够的空间时,复选框和文本一起转到新行。请如何实现它。
这是我如何编程方式添加复选框
if(attrs.length()>0)
{
LinearLayout attrControlsSubContainer = new LinearLayout(getBaseContext());
attrControlsSubContainer.setOrientation(LinearLayout.HORIZONTAL);
LinearLayout.LayoutParams layoutParams= new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT);
attrControlsSubContainer.setLayoutParams(layoutParams);
for(int i=0;i<attrs.length();i++)
{
CheckBox chkAttribute = new CheckBox(getBaseContext());
chkAttribute.setText(attrs.getJSONObject(i).getString("name"));
chkAttribute.setTextColor(Color.BLACK);
chkAttribute.setId(attrs.getJSONObject(i).getInt("id"));
attrControlsSubContainer.addView(chkAttribute);
}
attributeControlContainer.addView(attrControlsSubContainer);
}
相关[问题](http://stackoverflow.com/questions/ 14528381/android-horizontal-linearlayout-wrap-elements) – OJ7