具有layout_width = matchparent的TableLayout与父项不匹配 [英] TableLayout with layout_width=matchparent not matching parent

查看:67
本文介绍了具有layout_width = matchparent的TableLayout与父项不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个tableLayout有两列和两行,两行和最后一列的宽度都为match_parent,但是布局没有填充父级宽度,它像可包装的内容一样自如.

I have a tableLayout with two columns and two rows, both rows and the last column have match_parent for width but the layout isn't filling the parent width, it comports itself like it had wrap_content.

这是代码:

<TableLayout android:layout_width="match_parent">
    <TableRow android:layout_width="match_parent">
        <TextView 
            android:layout_width="wrap_content"
            android:text="static" />
        <EditText
            android:layout_width="match_parent"
            android:text="text" />
    </TableRow>

    <TableRow android:layout_width="match_parent">
        <TextView 
            android:layout_width="wrap_content"
            android:text="static2" />
        <EditText
            android:layout_width="match_parent"
            android:text="text2" />
    </TableRow>
</TableLayout>

对于具有父级宽度的每一行我需要做什么?

What I need to do for each line having the width of the parent?

Ps:我工作的地方不允许发布我的代码,因此我写的代码与我的代码尽可能接近.我不知道这是对的,我无法测试.

Ps: the place where I work don't allow me to post my code, so I write a code as close as possible of my code. I don't know if it is right, I can't test.

推荐答案

尝试以下代码,我认为它将为您提供帮助:

Try this code, I think it will help you:

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

    <TableRow android:layout_width="match_parent" >

        <TextView
            android:layout_width="fill_parent"
            android:layout_weight="1"
            android:text="static" />

        <EditText
            android:layout_width="match_parent"
            android:layout_weight="1"
            android:text="text" />
    </TableRow>

    <TableRow android:layout_width="match_parent" >

        <TextView
            android:layout_width="fill_parent"
            android:layout_weight="1"
            android:text="static2" />

        <EditText
            android:layout_width="match_parent"
            android:layout_weight="1"
            android:text="text2" />
    </TableRow>
</TableLayout> 

这篇关于具有layout_width = matchparent的TableLayout与父项不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆