I am developing an Android app. In my app I am adding checkboxes programmatically to a LinearLayout. But after the checkboxes are added, it does not properly fit to the layout.
Screenshot:
As you can see in screenshot "x-samll" text and its checkbox are not fitted properly. What I want is both checkbox and its text together go to new line when there is not enough space. How can I achieve it?
This is how I programmatically add checkboxes:
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);
}