0

I am adding button dynamically to a LinearLayout . The orientation is set to horizontal in the xml.I have two problems 1st the items are moving out of the view except for a few. The items need to push to the second row if they exceed the bounds. 2nd The buttons need to sit in the center of the screen with equal padding on both sides.

XML:

<LinearLayout
        android:id="@+id/ll1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:background="#F12312" 
        android:orientation="horizontal">
    </LinearLayout>

JAVA:

final LinearLayout Row = (LinearLayout)findViewById(R.id.ll2);
final LinearLayout TVRow = (LinearLayout)findViewById(R.id.ll1);


final Button[] my_button = new Button[Keys.size()];
final Button[] et = new Button[Texts.size()];

for (int bt = 0; bt < Keys.size(); bt ++){
final int Index = bt;
my_button[Index] = new Button(this);
my_button[Index].setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
my_button[Index].setText(Keys.get(Index));
my_button[Index].setId(Index);
my_button[Index].setGravity(Gravity.CENTER);
}
koherent
  • 370
  • 1
  • 3
  • 19

0 Answers0