I have a linearlayout and have to inflate variable number of buttons at runtime in this Linearlayout. Now my problem is that when I give Orientation for this linear layout. if I give it Horizontal or Vertical which create the problem. Will explain it with example:-
Eg1: Input is 3 buttons
Expected Output: Button1 Button2 Button3 ( If all 3 fits in one line completely)
All the 3 buttons should be displayed in this linear layout and in same line(just like horizontal) provided they fit completely.
Eg2: Input is 4 Buttons and they cannot fit in whole line
Expected output:- Line1:- Button1 Button2 (Assuming Button3 is not fitting completely in this line)
Line2:- Button3 Button4
Currently if I set LinearLAyout's orientation as Horizontal then its forcing all the 4 buttons in one line and the UI is getting screwed up. Same is the case if I give orientation as vertical.
Can someone tell me how to handle this at run time so that only complete buttons are displayed in one line and it spreads over multiple lines. Some generic way to handle this case.
The layout can be considered something like this for static purpose:-
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal">
<Button
android:id="@+id/button_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="YYYYYYYYYYYOOOOOOOOOOOOO"
android:textSize="75sp"/>
<Button
android:id="@+id/button_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="AAAAAAFFFFFFFFFFGGGGGGGGG"
android:textSize="75sp"/>
</LinearLayout>