android - 如何使 TableLayout 的宽度相同并换行内容

标签 android android-tablelayout

我尝试在 TextView 更改值时进行应用,然后 TableLayout 和 Text View 会将内容包装在一行文本中,第一个 TableRow 下面的表格行将遵循第一个 TableRow 的宽度。

这是我的代码 xml:

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:stretchColumns="1">

    <TableRow
        android:id="@+id/tableRow1"
        android:layout_height="wrap_content"
        android:layout_margin="10dp" >

        <!-- Column 1 -->
        <TextView
            android:id="@+id/textView1"
            android:layout_height="wrap_content"
            android:layout_width="0dip"
            android:layout_weight="1"
            android:text="I want This Layout in one line " />

        <!-- Column 2 -->
        <TextView
            android:id="@+id/textView2"
            android:layout_height="wrap_content"
            android:layout_width="0dip"
            android:layout_weight="1"
            android:text="This textview in one line" />

        <!-- Column 3 -->
        <TextView
            android:id="@+id/textView3"
            android:layout_height="wrap_content"
            android:layout_width="0dip"
            android:layout_weight="1"
            android:text="This to" />
    </TableRow>

    <!-- more rows
    <TableRow ... </TableRow>
    -->
</TableLayout>

My Layout

提前致谢

最佳答案

您需要将这两行添加到您的 TextView 中:

android:maxLines="1"
android:ellipsize="end"

这样,当您的文本长度超过一行中可以调整的长度时,它会在末尾省略

如果您使用的是 LinearLayout,那么一个简单的技巧就是将您的 LinearLayout 宽度设置为 wrap_content,然后父布局宽度将等于最大的子布局。然后您可以将 child 子的宽度设置为 match_parent,它将匹配所需 View 的宽度。

关于android - 如何使 TableLayout 的宽度相同并换行内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44512445/

相关文章:

Android Realm 一对多关系、查询

android - 如何以编程方式向简单的表格布局添加边框

android - TableLayout 行拉伸(stretch)/收缩

android - 如何在 Android 中读取彩信数据?

android - 如何使用 Android 加速度计?

android - 在 TableLayout 中设置 TableRow 的列

android - 如何在 TableLayout 周围添加边框?

android - 功能齐全的安卓数据网格

Android:收到新通知时如何打开屏幕?

c# - 使用 Akavache 在 ListView 适配器中显示图像