拉伸GridView

时间:2010-12-04 22:06:44

标签: android gridview

我在拉伸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>

SCREENSHOT:http://i53.tinypic.com/2poy136.jpg

1 个答案:

答案 0 :(得分:0)

您需要为嵌套layout_width定义GridView,以便其容器知道所需的空间:

<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以避免任何意外行为。