2010-12-04 114 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