Android Grid View Scroll Horizontally

回眸只為那壹抹淺笑 提交于 2019-12-05 05:19:16
Anton I. Sipos

This isn't easily possible with the stock Android GridView. Try using this library: two-way-gridview

(I found this library in this other answer: Horizontal scrolling grid view)

Is there any better way to do this?

Yes, there is.

You can achieve this in 3 lines using a RecyclerView with a horizontal GridLayoutManager:

RecyclerView recyclerView = (RecyclerView) findViewById(R.id.rec1);
recyclerView.setLayoutManager(new GridLayoutManager(this, 2, GridLayoutManager.HORIZONTAL, false));
recyclerView.setAdapter(new CustomAdapter(arrayList));

The RecyclerView supports applications built with the SDK 7 or larger.

If you want to make it even easier, take a look at the HorizontalGridView class if you are working with an application that is built for the API 17 or larger.


Here's a link of an example of a simple RecyclerView Adapter.

Harish

Try with below layout

 <HorizontalScrollView android="http://schemas.android.com/apk/res/android" 
        android:layout_width="wrap_content" android:layout_height="wrap_content">
        <GridView android:layout_width="wrap_content" android:layout_height="wrap_content" 
            android:id="@+id/gridview" android:columnWidth="50dp" android:padding="10dp" 
            android:horizontalSpacing="8dp" android:verticalSpacing="12dp" 
            android:numColumns="3" android:scrollbars="horizontal"/>
    </HorizontalScrollView>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!