Android TableRow未包装TextView

Android TableRow未包装TextView,android,android-layout,android-tablelayout,Android,Android Layout,Android Tablelayout,TableLayout在每行上都有一个TextView和EditText。当EditText有多行时,TableRow将其包装,但当TextEdit时,它不包装 简化布局: <?xml version="1.0" encoding="utf-8"?> <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent"

TableLayout在每行上都有一个
TextView
EditText
。当
EditText
有多行时,
TableRow
将其包装,但当
TextEdit
时,它不包装

简化布局:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:shrinkColumns="*" >

    <TableRow>

        <TextView
            android:id="@+id/textView1"
            android:text="Lorem ipsum dolor sit amet, consectetur" />

        <EditText
            android:id="@+id/textView2"
            android:text="Foo" />
    </TableRow>

    <TableRow>

        <TextView
            android:id="@+id/textView3"
            android:text="Foo" />

        <EditText
            android:id="@+id/textView4"
            android:text="Lorem ipsum dolor sit amet, consectetur" />
    </TableRow>

</TableLayout>
呈现为:

要让Android正确呈现第一个布局,我应该怎么做


Ps:我已经尝试将
android:layout\u width=“fill\u parent”
android:layout\u height=“wrap\u content
”属性添加到
TableRow
TextView
EditText
控件,没有任何更改。

尝试添加到TableLayout

 android:stretchColumns="*"
如果tat也不起作用,试着增加重量

                <TableRow
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="2" >


And to the TextView and EditText add 
              android:layout_weight="1"          

并添加到TextView和EditText
android:layout_weight=“1”

添加
android:layout\u gravity=“center\u vertical”
TextView
或添加
android:background=“#B0B0B0”
EditText
强制android正确渲染。


<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:shrinkColumns="*" >

    <TableRow>

        <TextView
            android:id="@+id/textView1"
            android:text="Lorem ipsum dolor sit amet, consectetur" />

        <TextView
            android:id="@+id/textView2"
            android:text="Foo" />
    </TableRow>

    <TableRow>

        <TextView
            android:id="@+id/textView3"
            android:text="Foo" />

        <TextView
            android:id="@+id/textView4"
            android:text="Lorem ipsum dolor sit amet, consectetur" />
    </TableRow>

</TableLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:weightSum="4" >

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginRight="1dp"
                android:layout_weight="1"
                android:background="#B0B0B0" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginRight="1dp"
                android:layout_weight="1"
                android:background="#B0B0B0" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginRight="1dp"
                android:layout_weight="1"
                android:background="#B0B0B0" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="#B0B0B0" />
        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="1dp"
            android:orientation="vertical"
            android:weightSum="4" >

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginRight="1dp"
                android:layout_weight="1"
                android:background="#B0B0B0" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginRight="1dp"
                android:layout_weight="1"
                android:background="#B0B0B0" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginRight="1dp"
                android:layout_weight="1"
                android:background="#B0B0B0" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="#B0B0B0" />
        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="1dp"
            android:orientation="vertical"
            android:weightSum="4" >

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginRight="1dp"
                android:layout_weight="1"
                android:background="#B0B0B0" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginRight="1dp"
                android:layout_weight="1"
                android:background="#B0B0B0" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginRight="1dp"
                android:layout_weight="1"
                android:background="#B0B0B0" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="#B0B0B0" />
        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="1dp"
            android:orientation="vertical"
            android:weightSum="4" >

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginRight="1dp"
                android:layout_weight="1"
                android:background="#B0B0B0" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginRight="1dp"
                android:layout_weight="1"
                android:background="#B0B0B0" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginRight="1dp"
                android:layout_weight="1"
                android:background="#B0B0B0" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="#B0B0B0" />
        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="1dp"
            android:orientation="vertical"
            android:weightSum="4" >

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginRight="1dp"
                android:layout_weight="1"
                android:background="#B0B0B0" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginRight="1dp"
                android:layout_weight="1"
                android:background="#B0B0B0" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginRight="1dp"
                android:layout_weight="1"
                android:background="#B0B0B0" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="#B0B0B0" />
        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="1dp"
            android:orientation="vertical"
            android:weightSum="4" >

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginRight="1dp"
                android:layout_weight="1"
                android:background="#B0B0B0" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginRight="1dp"
                android:layout_weight="1"
                android:background="#B0B0B0" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginRight="1dp"
                android:layout_weight="1"
                android:background="#B0B0B0" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="#B0B0B0" />
        </TableRow>
    </TableLayout>

</LinearLayout>
这些灰色单元格是文本框


我也遇到了同样的问题,解决所有问题的方法是为我想要进行word包装的文本视图设置权重


我的两分钱…

那么这个答案和问题之间的相关性是什么呢?只需在其中输入文本值,您就会发现如何在表格行中呈现文本正如我在问题中提到的,当两个控件都是TextEdit时,它会正确呈现。我尝试逐个添加xml属性。。只需将android:background=“#b0b0”添加到EditText即可使android呈现正确的布局。奇怪..荒谬的:D:D:DWow,它真的有效!不知何故,权重克服了TextView中的一个bug(毫无疑问,这是一个副作用)。下面是一条命令,供有兴趣添加到TextView的xml布局中的人使用:
android:layout\u weight=“1”
。是的,成功了。