我有一个包含两列和两行的 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/