【问题标题】:How can I stretch the cells of the GridView vertically?如何垂直拉伸 GridView 的单元格?
【发布时间】:2012-08-07 09:41:28
【问题描述】:

我有这个 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>

这个布局将用于其中的项目:

<?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>

结果:

我想将单行单元格拉伸为与多行单元格一样长。我该怎么做?

我已经为 textViews 设置了android:layout_height="match_parent",但它不影响。

【问题讨论】:

    标签: android gridview row-height


    【解决方案1】:

    将您的 TextView 设置为显示 2 行:

    <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" />
    

    【讨论】:

    • 你也可以使用属性:android:minLines="2",这样视图至少会显示2行
    • 一个单元格可能有 1 或 5 行。如果我将其设置为 5,则 1 行单元格有空行,如果我将其设置为 1,则 5 行行未完全显示。有没有办法可以一起调整线条?
    • 您始终可以将单元格重力设置为居中,这样文本将垂直和水平居中:android:gravity="center"
    猜你喜欢
    • 1970-01-01
    • 2021-12-31
    • 2011-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多