How can I stretch the cells of the GridView vertic

2019-05-26 14:37发布

问题:

I have this GridView:

<GridView     android:id="@+id/gridEtebarSanji"
              android:layout_width="match_parent"
              android:layout_height="480dp"
              android:background="@color/black"
              android:gravity="center"
              android:horizontalSpacing="2dp"
              android:isScrollContainer="false"
              android:numColumns="3"
              android:stretchMode="columnWidth"
              android:verticalSpacing="2dp" >

  </GridView>

And this layout to be used for the item inside of it:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center_horizontal" >

    <TextView
        android:id="@+id/tvText"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/white"
        android:singleLine="false"
        android:text="TextView"
        android:textSize="16dip" />

</LinearLayout>

And the result:

I want to stretch single line cells to be as long as multi-line cells. How can I do that?

I have set android:layout_height="match_parent" for textViews but it does not affect.

回答1:

Set your TextView to display 2 lines:

<TextView
        android:id="@+id/tvText"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/white"
        android:lines="2"
        android:text="TextView"
        android:textSize="16dip" />