Android TableRow儿童问题

时间:2012-04-19 15:04:41

标签: android width tablelayout children tablerow

我的TableLayout目前有3行,每行有一个孩子,TextView。我的问题是TextViews宽度不应该"match_parent"。我已经遵循了不为它们定义高度和宽度的过程(like the documentation says),但由于某种原因,问题仍然存在。

我打开了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>

1 个答案:

答案 0 :(得分:13)

我不知道为什么会这样,但你可以通过添加:

来避免这个问题
android:layout_weight="1"

给您的孩子TextView,或者添加:

android:stretchColumns="0"

发送给您的父TableLayout