2014-02-20 53 views
0

我想做一個網格視圖,它有很多圖像。所以我想讓它水平滾動,但它不滾動。如何製作水平滾動的網格視圖?請幫幫我。 這是我的代碼。如何製作水平滾動的網格視圖?

<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> 
+1

檢查這個http://stackoverflow.com/questions/13236123/how-to-make-grid-view-horizo​​ntally-scrollable-in-android?rq=1 –

+0

我檢查它,跟它添加一些插件,我不想使用任何插件。 –

+1

其不插入..在庫..如果你不想使用任何第三方庫,然後編寫自己的自定義gridview .. –

回答

0

我得到了答案,我在這裏分享。

只需進入以下鏈接: - Link只需將此庫添加到您的項目中即可。之後,只需在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"/> 

正常後只需將以下代碼應用於您的java文件。

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