android - 具有 layout_width=matchparent 的 TableLayout 不匹配父级

标签 android android-layout android-tablelayout

我有一个包含两列和两行的 tableLayout,两行和最后一列的宽度都有 match_parent,但布局没有填充父宽度,它本身就像有 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>

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

Ps:我工作的地方不允许我贴出我的代码,所以我写了一个尽可能接近我代码的代码。不知道对不对,没法测试。

最佳答案

试试这段代码,我认为它会对你有所帮助:

  <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> 

关于android - 具有 layout_width=matchparent 的 TableLayout 不匹配父级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16714388/

相关文章:

java - 有助于在 Android 中进行代码检查的工具

android - 如何使用GreenDao直接保存protocol buffer类

android - android 中的 ListView 计数与适配器计数

android - 如何设置tablerows元素的权重?

android - TableLayout - 具有相同 layout_weight 的 TableRows 不具有相同的高度

android - TableRow 中的 SeekBar 宽度?

android - 如何使一个 ViewModel 类向 Activity 或 fragment 返回多种数据类型

java - 如何解决在另一个 Activity 中搜索标题打不开实际描述的问题?

android - 如果在底部,ExpandableListView 不会滚动

android - 如何禁用图库中的滚动