我正在開發一個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