Android TableRow 儿童问题



我目前有一个 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.

最新更新