9

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.

Sanchit Paurush
  • 6,114
  • 17
  • 68
  • 107

3 Answers3

5
        <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>
Ashish Soni
  • 286
  • 3
  • 4
  • 1
    I use your nested structure and added adapter like doc says, but only 3 image appears under each other and drig is not scrollable, do you know why? https://developer.android.com/guide/topics/ui/layout/gridview.html – János Jul 12 '16 at 06:06
2

you can use third party library two-way grid view. it works great for horizontal scrolling or you can use RecyclerView

Community
  • 1
  • 1
H Raval
  • 1,903
  • 17
  • 39
1

You can try putting the GridView in a HorizontalScrollView. You may try to set fixed height to the GridView inside the HorizontalScrollView.

Then you can dynamically calculate the number of columns of the GridView based on your content and use setNumColumns(int) method to set it.

jaibatrik
  • 6,770
  • 9
  • 33
  • 62