Android Linearlayout In Horizontalscrollview With Multiple Rows
I am using LinearLayout in HorizontalScrollView the scrolling part is working but i can't figure out how to make 3 rows. for Example: Bold shows what is currently displayed (in em
Solution 1:
Instead of LinearLayout Try GridLayout which is part of Android support library.
It has provision of setting number of columns and rows while implementation in XML layout.
Something like below
<HorizontalScrollViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginTop="50dp" ><GridLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:columnCount="6"android:rowCount="3"android:orientation="horizontal" ><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Button1" /><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Button2" /><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Button3" /><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Button4" /><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Button5" /><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Button6" /><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Button7" /><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Button8" /><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Button9" /><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Button10" /><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Button11" /><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Button12" /></GridLayout></HorizontalScrollView>
Edit - You can use TableLayout instead of GridLayout if you want to add child views of different width as below
<HorizontalScrollViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginTop="50dp" ><TableLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content" ><TableRowandroid:layout_width="match_parent"android:layout_height="wrap_content" ><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Button1" /><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Button2" /><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Button3" /><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Button4" /><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Button5" /><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Button6" /></TableRow><TableRowandroid:layout_width="match_parent"android:layout_height="wrap_content" ><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Button7" /><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Button8" /><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Button9" /><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Button10" /><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Button11" /><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Button12" /></TableRow></TableLayout></HorizontalScrollView>
Post a Comment for "Android Linearlayout In Horizontalscrollview With Multiple Rows"