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

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

问题描述

我有一个包含两列两行的 tableLayout,两行和最后一列的宽度都有 match_parent,但布局没有填充父宽度,它本身就像它有 wrap_content 一样.

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天全站免登陆