2013-01-05 30 views

回答

18

GridView並非真正爲此目的而設計的,它旨在以高效的滾動方式顯示無限數量的數據。如果您想創建一個靜態佈局,您可以將項目分散放置在特定位置,則應該查看GridLayoutTableLayout

+8

這個答案是正確的,但如果你仍然想使用gridview,那麼你可以設置android:numColumns =「10」,然後在你的適配器中,你可以給它100個項目,這應該導致10x10網格視圖,享受。 – DraganescuValentin

0

如果您有100個項目,則只會顯示10行。沒有必要有固定數量的行。

+0

如果我們需要固定數量的行和列的應用程序,如菱形破折號遊戲。我們如何設置固定的行數? – Ann

+0

我想Devunwired有答案。 –

+0

我已經創建了一個GridView並使用適配器在其中插入了9個項目。但它只顯示一行(3項)。我錯過了什麼。 –

0

行數自動計算(和你強加)從 列數和項目數

+0

我們需要固定數量的行和列,像菱形破折號遊戲這樣的應用程序。不會有任何第二行。 – 2014-07-20 05:36:36

5

我不建議,但如果你使用的API 14大於14,你可以使用此代碼列 集數和行

從XML

<GridLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/GridLayout1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:columnCount="2" 
    android:rowCount="2" 
    android:orientation="horizontal" 
    tools:context=".GridXMLActivity" > 

從Java

setRowCount(int rownumber); 

享受

0

我用這樣的事情,它不是GridView的,但我有類似的問題和網格佈局幫了我很多:

<GridLayout 
    android:id="@+id/bottom_recycle_view" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:columnCount="10" 
    android:rowCount="10" 
> 

您將有10行10列。

相關問題