【问题标题】:TableLayout border issue AndroidTableLayout边框问题Android
【发布时间】:2014-02-24 22:49:06
【问题描述】:

我有一个表格,表格的每一行都有一个边框。当一列中的文本进入第二行时,边框部分出现问题,而另一列中的文本没有。这会导致没有将文本包裹到第二行的行更短,并且第二行的背景为黑色。如何使该行与另一行的高度相同?

我的代码是:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="#013567" >

    <TableLayout
        android:id="@+id/tableLayout1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:shrinkColumns="*"
        android:stretchColumns="*" >

        <TableRow
            android:id="@+id/tableRow2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#000" >

        <TextView
            android:id="@+id/textView2"
            android:layout_margin="2dip"
            android:background="#013567"
            android:gravity="center"
            android:text="long text abc 123 ong tex ong tex"
            android:textColor="#fff" >
        </TextView>

        <TextView
            android:id="@+id/textView3"
            android:layout_margin="2dip"
            android:background="#013567"
            android:gravity="center"
            android:text="short text"
            android:textColor="#fff" >
        </TextView>
    </TableRow>

    <TableRow
        android:id="@+id/tableRow2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#000" >

        <TextView
            android:id="@+id/textView2"
            android:layout_margin="2dip"
            android:background="#013567"
            android:gravity="center"
            android:text="short text"
            android:textColor="#fff" >
        </TextView>

        <TextView
            android:id="@+id/textView3"
            android:layout_margin="2dip"
            android:background="#013567"
            android:gravity="center"
            android:text="long text abc 123 ong tex ong tex"
            android:textColor="#fff" >
        </TextView>
    </TableRow>
</TableLayout>
</ScrollView>

示例:

【问题讨论】:

标签: android tablelayout tablerow


【解决方案1】:

将以下属性添加到您的TextView,而不是您的TableRow

android:layout_height="match_parent"

android:layout_height="fill_parent"(已弃用)

【讨论】:

    【解决方案2】:

    尝试将以下内容设置为您的TableRow

    android:layout_height="fill_parent"
    

    【讨论】:

      【解决方案3】:

      在“短文本”的 en 中添加新行

      以编程方式:

      • \n

      xml:

      • 只需在您的 XML 代码中按 Enter 键

      【讨论】:

      • 但是在横向和更大的屏幕上,其他文本短文本框更大。
      【解决方案4】:

      有几种方法可以解决这个问题,

      使用android:layout_height="match_parent"在每个文本周围添加一个FrameLayout。

      更改您的样式以应用于表格,例如

      How to style a tablelayout in android

      将表格背景设置为蓝色,边框设置为黑色。

      【讨论】:

      • 当我尝试添加对我不起作用的框架布局时,但您给我的另一个链接帮助了我(删除了几行我不需要的代码)!
      • 是的,我应该提到,在大多数情况下,这是更好的方式,因为样式是在桌面上而不是在文本上。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多