ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Android TableRow儿童问题

2019-07-14 22:33:59  阅读:294  来源: 互联网

标签:android width tablelayout children tablerow


我有一个目前有3行的TableLayout,每行有一个子项,一个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文件.也许问题在那里? (文本行代码来自这里提供的关于边界问题的解决方案)我非常理解它,我认为它不应该影响我的问题,但我可能是错的.无论如何,这里是:

<?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"

给你的孩子TextViews,或添加:

android:stretchColumns="0"

到您的父TableLayout.

标签:android,width,tablelayout,children,tablerow
来源: https://codeday.me/bug/20190714/1461738.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有