2

I have a grid view in my application and i need to scroll it horizontally.Can you tell me how to do it. i did like this android:scrollbarAlwaysDrawHorizontalTrack="true" but it is not working.

Thanks

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="#E6EBF3" >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Food" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Beverages" />
</LinearLayout>

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="#E6EBF3" >

    <LinearLayout
        android:id="@+id/linearLayoutHeader"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1" >
    </LinearLayout>

    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:gravity="right|center_horizontal"
        android:hint="search your favorite" />
</LinearLayout>

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:background="#A1A7B0" >

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="#A1A7B0"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/popular"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="right|center_horizontal"
                android:paddingRight="10dp"
                android:text="Popular" />

            <TextView
                android:id="@+id/popular"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="right|center_horizontal"
                android:text="New" />
        </LinearLayout>


        <GridView
            android:id="@+id/gridView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:numColumns="auto_fit"
            android:scrollbarAlwaysDrawHorizontalTrack="true" >
        </GridView>
    </LinearLayout>

    <LinearLayout
        android:layout_width="200dp"
        android:layout_height="match_parent"
        android:background="#CED1CF" >
    </LinearLayout>
</LinearLayout>

Narendra
  • 1,868
  • 6
  • 25
  • 39

3 Answers3

1

Wrap the GridView in HorizontalScrollView.

a.ch.
  • 8,285
  • 5
  • 40
  • 53
  • No, wrapping will kill GridView virtualization (loading elements only when they are visible). Better make your own GridView implementation with horizontal scrolling. – Triang3l Jul 08 '13 at 09:31
1

GridView doesn't support horizontal scroll.

Kannan Suresh
  • 4,573
  • 3
  • 34
  • 59
  • Check: http://stackoverflow.com/questions/2997818/gridview-with-horizontal-scroll and http://stackoverflow.com/questions/5725745/horizontal-scrolling-grid-view – Kannan Suresh Dec 20 '11 at 09:07
1

I think GridView doesn't support horizontal scrolling.

We have to create the grid view functionality with horizontal scroll. See this link about Grid View with horizontal scroll. It may help you.

Horizontal scrolling grid view

Community
  • 1
  • 1
Yugandhar Babu
  • 10,311
  • 9
  • 42
  • 67