我目前有一个 3 行的TableLayout
,每行有一个孩子,一个TextView
。我的问题是TextViews
宽度没有按应有的方式"match_parent"
。我遵循了不为它们定义高度和宽度的过程(如文档所述),但由于某种原因问题仍然存在。
我已经打开了hierarchyviewer
并查看了值,TableRow
填充了应有的宽度,但TextView
没有填充行,它只是包装了内容。完整的xml布局如下,有人有什么想法吗?
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:background="@drawable/textlines"
android:text="@string/text1_string"
android:textColor="#000000"
android:padding="5dp">
</TextView>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:background="@drawable/textlines"
android:text="@string/text1_string"
android:textColor="#000000"
android:padding="5dp">
</TextView>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:background="@drawable/textlines"
android:text="@string/text1_string"
android:textColor="#000000"
android:padding="5dp">
</TextView>
</TableRow>
</TableLayout>
此外,我还将包括@drawable/textlines
的 xml 文件。也许问题就在那里?(textlines
代码取自此处提供的有关边界问题的解决方案)我几乎理解它,我认为它不会影响我的问题,但我可能是错的。无论如何,这里是:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape
android:shape="rectangle">
<stroke android:width="1dp" android:color="#FF000000" />
<solid android:color="#FFDDDDDD" />
</shape>
</item>
<item android:top="1dp" android:bottom="1dp">
<shape
android:shape="rectangle">
<stroke android:width="1dp" android:color="#FFDDDDDD" />
<solid android:color="#00000000" />
</shape>
</item>
</layer-list>
为什么会发生这种情况,但您可以通过添加以下内容来避免该问题:
android:layout_weight="1"
给您的孩子TextView
s,或通过添加:
android:stretchColumns="0"
到您的父母TableLayout
.