2010-12-04 122 views
2

Im在拉伸我的GridView以適應Display-Width時出現問題。任何人都知道如何解決這個問題?我想在GridView佔據整個寬度包括藍色標記字段(見下圖)拉伸GridView

<TableRow> 
    <ProgressBar 
     android:id="@+id/timeBar" 
     style="?android:attr/progressBarStyleHorizontal" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="4" 
    /> 

    <TextView 
     android:id="@+id/points" 
     android:gravity="center" 
     android:textColor="#FFE7BA" 
     android:textSize="18px" 
     android:layout_width="fill_parent" android:layout_height="fill_parent" 
     android:layout_weight="1" 
    /> 
</TableRow> 

<TableRow 
android:layout_weight="1" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 
    <TextView 
     android:text="KANJI" 
     android:gravity="center_horizontal" 
     android:background="#aa0000" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="2" 
     /> 
</TableRow> 

<TableRow> 
    <GridView 
     android:id="@+id/gridview" 
     android:numColumns="2" 
     android:layout_gravity="center" 
     android:stretchMode="columnWidth" 
     /> 
</TableRow> 

截圖:http://i53.tinypic.com/2poy136.jpg

+1

一個GridView不是一個GridLayout。請更改您的問題標題。 – pjv 2012-12-20 17:03:51

回答

0

您需要爲您的嵌套定義一個layout_widthGridView以便它的容器知道它需要多少空間:

<TableRow> 
    <!-- added the line android:layout_width="fill_parent" --> 
    <GridView 
     android:id="@+id/gridview" 
     android:layout_width="fill_parent" 
     android:numColumns="2" 
     android:layout_gravity="center" 
     android:stretchMode="columnWidth" /> 
</TableRow> 

您還應該提供一個layout_height以避免任何意外的行爲。

+0

android:layout_width =「wrap_content」是正確的代碼! :) – Filly 2010-12-06 22:55:23