Android TableRow儿童问题

Android TableRow儿童问题,android,width,tablelayout,children,tablerow,Android,Width,Tablelayout,Children,Tablerow,我有一个TableLayout,目前有3行,每行有一个子项TextView。我的问题是TextViews宽度与“匹配父项”不匹配。我遵循了不为它们定义高度和宽度()的过程,但出于某种原因,问题仍然存在 我已经打开了hierarchyviewer并查看了值,TableRow按应有的宽度填充,但是TextView没有填充行,它只是包装了内容。下面是完整的xml布局,有人有什么想法吗 <?xml version="1.0" encoding="utf-8"?> <TableLayou

我有一个
TableLayout
,目前有3行,每行有一个子项
TextView
。我的问题是
TextViews
宽度与
“匹配父项”
不匹配。我遵循了不为它们定义高度和宽度()的过程,但出于某种原因,问题仍然存在

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

我不知道为什么会发生这种情况,但您可以通过添加以下内容来避免该问题:

android:layout_weight="1"
android:stretchColumns="0"
给您的孩子
TextView
s,或通过添加:

android:layout_weight="1"
android:stretchColumns="0"

对于您的家长
TableLayout

@DanDar3是的,将宽度设置为1不会解决任何问题。如果您认为您可以更正问题/答案,请不要害怕编辑它。要以编程方式拉伸所有列,请使用SetStretCharlColumns(true);您可以通过以下方式尝试
android:stretchColumns=“*”