我尝试在 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>
提前致谢
最佳答案
您需要将这两行添加到您的 TextView 中:
android:maxLines="1"
android:ellipsize="end"
这样,当您的文本长度超过一行中可以调整的长度时,它会在末尾省略
如果您使用的是 LinearLayout,那么一个简单的技巧就是将您的 LinearLayout 宽度设置为 wrap_content,然后父布局宽度将等于最大的子布局。然后您可以将 child 子的宽度设置为 match_parent,它将匹配所需 View 的宽度。
关于android - 如何使 TableLayout 的宽度相同并换行内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44512445/