2010-12-13 81 views
7

所以讓我們嘗試解釋什麼,我試圖做...是否可以創建一個具有不同大小子項的GridView?

我有一個設計,看起來像這樣 - !

[替代文本] [1]

爲此,我有我創建了兩個GridView的,像這樣:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:orientation="vertical" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content"> 

    <LinearLayout android:orientation="vertical" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content"> 

     <TextView style="@style/GroupName" 
        android:text="@string/currency_badges"/> 

     <GridView android:id="@+id/currency_grid" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:columnWidth="90dp" 
        android:numColumns="auto_fit" 
        android:verticalSpacing="10dp" 
        android:horizontalSpacing="10dp" 
        android:stretchMode="columnWidth" 
        android:gravity="left"/> 

    </LinearLayout> 

    <LinearLayout android:orientation="vertical" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content"> 

     <TextView style="@style/GroupName" 
        android:text="@string/foursquare_badges"/> 

     <GridView android:id="@+id/foursquare_grid" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:columnWidth="90dp" 
        android:numColumns="auto_fit" 
        android:verticalSpacing="10dp" 
        android:horizontalSpacing="10dp" 
        android:stretchMode="columnWidth" 
        android:gravity="left"/> 

    </LinearLayout> 
</LinearLayout> 

我不是真的喜歡它,因爲你可以看到右上角圖標的標籤是隱藏的。我可以點擊並滾動,但這不是我想要的。另外更大的問題是每個GridView都有它自己的SCROLLBAR。再次不是我想要的。所以我想我想用一個GridView來完成這個。如何使用GridView來創建圖標,然後在圖標中間顯示GroupName。我知道我可以創建一個BaseAdapter來返回不同類型的視圖,但我需要有一個項目橫向佔據整個空間。這可能嗎?

編輯:

我想一個更好的問題是如何創建分組GridView的?

回答

0

我不確定您現在如何添加項目,但您可以使用SimpleAdapter。它使您可以提供xml佈局,並將數據對象中的項目映射到xml佈局中的位置。如果您進行快速搜索,有許多教程可供使用。

+0

這就是我現在正在做的。除了我正在使用BaseAdapter。我知道我可以返回不同的意見。我的問題是,當我將寬度設置爲fill_parent時,它不起作用。 – 2010-12-14 00:20:19

+0

對不起,我想我誤解了你的問題(儘管SimpleAdapter可能比BaseAdapter更容易使用)。你在說你想要一個支持多個部分的小部件,每個部分都有一個GridView。我不認爲有任何這樣的小工具,你需要創建自己的。你期望展示多少圖標?如果你不關心對象重用GridView給你,你可能很容易用ScrollView中的LinearLayout或TableLayout完成你想要的。 – 2010-12-14 01:35:05

+0

經過慎重考慮,我認爲這是不可能的。你是對的,我需要創建我自己的小部件,這是不值得我現在的時間。 – 2010-12-19 18:04:32

相關問題