2012-04-19 108 views
3

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

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

回答

13

我不知道为什么发生这种情况,但你可以避开这个问题通过添加:

android:layout_weight="1" 

给你的孩子TextView S,或通过添加:

android:stretchColumns="0" 

给你的父母TableLayout

+0

我想你的意思是: '机器人:layout_weight = “1”' 到TextView的... – 2012-09-01 20:15:45

+1

@ DanDar3是,宽度设置为1不能解决任何问题。如果您认为可以更正问题,请不要害怕编辑问题/答案。 – Luksprog 2012-09-02 06:54:00

+0

用于以编程方式扩展所有列*使用setStretchAllColumns(true); – 2014-01-29 17:12:18