简体   繁体   English

如何制作水平滚动网格视图?

[英]How to make Horizontally scrollable Grid View?

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>

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. 之后,只需在Grid View代码处使用xml代码即可。

 <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. 正常情况下只需在您的java文件中应用以下代码。

TwoWayGridView scrollview;
scrollview = (TwoWayGridView) findViewById(R.id.grid_viewlevel);
mAdapter = new LevelAdapter(this, R.layout.levelselect);
scrollview.setAdapter(mAdapter);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM