【问题标题】:Match height of all tablerow匹配所有 tablerow 的高度
【发布时间】:2016-01-10 18:03:08
【问题描述】:

如图所示,我正在尝试填充左侧的短文本以匹配右侧的长文本。 rihtsite 上的长文本会动态变化,因此不会是静态的。

这是我的代码:

        <TableLayout
            android:id="@+id/table"
            android:layout_margin="10dp"
            android:layout_below="@id/avatar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <TableRow
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
                <TextView android:text="short text"
                    android:gravity="center"
                    android:stretchColumns="1"
                    android:layout_width="0px"
                    android:layout_height="wrap_content"
                    android:layout_column="1"
                    android:layout_weight="1"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:padding="5dp"
                    android:background="@drawable/xml_cell_shape"/>
                <TextView android:text="long text is long really really long this is not a lie"
                    android:layout_width="0px"
                    android:layout_height="wrap_content"
                    android:layout_column="2"
                    android:layout_weight="3"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:padding="5dp"
                    android:background="@drawable/xml_cell_shape"/>
            </TableRow>
            <TableRow
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
                <TextView android:text="short text"
                    android:layout_width="0px"
                    android:layout_height="wrap_content"
                    android:layout_column="1"
                    android:layout_weight="1"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:padding="5dp"
                    android:background="@drawable/xml_cell_shape"/>
                <TextView android:text="medium text not long nor short"
                    android:layout_width="0px"
                    android:layout_height="wrap_content"
                    android:layout_column="2"
                    android:layout_weight="3"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:padding="5dp"
                    android:background="@drawable/xml_cell_shape"/>
            </TableRow>
        </TableLayout>

【问题讨论】:

    标签: android xml tablelayout


    【解决方案1】:

    只需将您的 TextViews 包装在一个 LinearLayout 中的 TableRow 中。像这样

    <TableRow
            android:layout_width="match_parent"
            android:layout_height="match_parent">
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="4"
                android:orientation="horizontal">
    
                <TextView
                    android:layout_width="0dip"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:background="@drawable/xml_cell_shape"
                    android:gravity="center"
                    android:padding="5dp"
                    android:text="short text"
                    android:textAppearance="?android:attr/textAppearanceMedium"/>
    
                <TextView
                    android:layout_width="0dip"
                    android:layout_height="match_parent"
                    android:layout_weight="3"
                    android:background="@drawable/xml_cell_shape"
                    android:padding="5dp"
                    android:gravity="center"
                    android:text="long text is long really really long this is not a lie"
                    android:textAppearance="?android:attr/textAppearanceMedium"/>
            </LinearLayout>
        </TableRow>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-08
      • 2011-09-18
      • 2010-11-17
      • 2019-09-04
      • 2018-07-21
      • 1970-01-01
      • 2015-10-28
      • 1970-01-01
      相关资源
      最近更新 更多