0

I am trying to make a Grid View and it has a lot of images. So I want to make it Horizontally scrollable, but it is not scrolling. How to make Horizontally scrollable Grid View ? Please help me. Here is my code.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent" >
<HorizontalScrollView 
   android:id="@+id/horizontalScrollView1" 
   android:layout_width="fill_parent" 
   android:layout_height="wrap_content"
   android:fillViewport="true"
   android:scrollbars="horizontal" >
<GridView
   android:layout_width="500dp"
   android:layout_height="400dp"
   android:id="@+id/gridview"
   android:columnWidth="300dp"
   android:numColumns="3"
   android:horizontalSpacing="10dp"
   android:scrollbars="horizontal">
</GridView>
 </HorizontalScrollView>
</RelativeLayout>
Amit Jayaswal
  • 1,725
  • 2
  • 19
  • 36

1 Answers1

0

I got the answer, and I am sharing here.

Just go on the following link:- Link and just add this library into your project. After that just use the xml code at the place of Grid View code.

 <com.jess.ui.TwoWayGridView
   xmlns:app="http://schemas.android.com/apk/res-auto"
   android:id="@+id/grid_viewlevel"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   app:gravity="center"
   app:columnWidth="200dp"
   app:rowHeight="200dp"
   app:numColumns="15"
   app:numRows="2"
   app:verticalSpacing="0dp"
   app:horizontalSpacing="0dp"
   app:stretchMode="columnWidth"
   app:scrollDirectionPortrait="horizontal"
   app:scrollDirectionLandscape="horizontal"/>

After normally Just apply the following code in your java file.

TwoWayGridView scrollview;
scrollview = (TwoWayGridView) findViewById(R.id.grid_viewlevel);
mAdapter = new LevelAdapter(this, R.layout.levelselect);
scrollview.setAdapter(mAdapter);
Amit Jayaswal
  • 1,725
  • 2
  • 19
  • 36