How to make grid view scroll horizontally not vertically in android?

Sanchit Paurush picture Sanchit Paurush · Apr 10, 2013 · Viewed 32.5k times · Source

I have a dynamic Grid View. Means its content varies. So, if the number of items increases it makes vertical scroll. I want to make it as horizontal scroll.

Please suggest some solution for this.

Answer

Ashish Soni picture Ashish Soni · Mar 21, 2016
        <HorizontalScrollView
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:layout_below="@+id/seatLegendLayout">

        <FrameLayout
            android:layout_width="fill_parent"
            android:layout_height="match_parent">

            <LinearLayout
                android:id="@+id/linearLayout_gridtableLayout"
                android:layout_width="900dp"
                android:layout_height="match_parent"
                android:orientation="horizontal">

                <GridView
                    android:id="@+id/gridView1"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_margin="4dp"
                    android:columnWidth="100dp"
                    android:gravity="center"
                    android:numColumns="9"
                    android:horizontalSpacing="1dp"
                    android:scrollbarAlwaysDrawHorizontalTrack="true"
                    android:scrollbarAlwaysDrawVerticalTrack="true"
                    android:scrollbars="horizontal"
                    android:stretchMode="none"
                    android:verticalSpacing="1dp">

                </GridView>


            </LinearLayout>
        </FrameLayout>
    </HorizontalScrollView>