简体   繁体   English

Android TableView和TextView作为单元格 - 如何将TextView设置为多行

[英]Android TableView and TextView as cell - how to setup TextView to be multiline

I have a TableView with TextView as cell elements. 我有一个带TextView的TableView作为单元格元素。 Currently I can't setup the layout file so that the TextView texts are multilined when the text width is wider than the cell width. 目前我无法设置布局文件,以便当文本宽度比单元格宽度宽时,TextView文本是多行的。 It always end up with table cell growing width exceeding the screen width. 它总是以表格单元增长宽度超过屏幕宽度结束。 How to fix this? 如何解决这个问题?

Try something like this: 尝试这样的事情:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:orientation="vertical">
    <TableLayout android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:stretchColumns="*"
        android:id="@+id/tableLayout1">
        <TableRow android:id="@+id/tableRow1" android:layout_width="fill_parent"
            android:layout_height="wrap_content">
            <TextView android:text="test1" android:layout_width="fill_parent"
                android:layout_height="wrap_content" android:layout_weight="0" />
            <TextView android:layout_weight="1"
                android:text="test2 very long text that needs to be wrapped properly using layout_weight property and ignoring singleline since that is set by default..."
                android:layout_width="fill_parent" android:layout_height="wrap_content" />
        </TableRow>     
    </TableLayout>
</LinearLayout>

为TextView设置固定宽度,一切都应该有效......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM