【问题标题】:Android TableRow children issueAndroid TableRow 儿童问题
【发布时间】:2012-09-02 14:52:57
【问题描述】:

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

【问题讨论】:

    标签: android width tablelayout children tablerow


    【解决方案1】:

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

    android:layout_weight="1"
    

    给您的孩子TextViews,或添加:

    android:stretchColumns="0"
    

    致你的父母TableLayout

    【讨论】:

    • @DanDar3 是的,将宽度设置为 1 并不能解决任何问题。如果您认为可以更正,请不要害怕编辑问题/答案。
    • 对于所有列以编程方式使用 setStretchAllColumns(true);
    • 你可以通过developer.android.com尝试android:stretchColumns="*"
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-30
    相关资源
    最近更新 更多