【发布时间】:2014-05-27 08:55:13
【问题描述】:
我有问题。我有一个很少垂直线性布局的视图,它们都有背景,其中一个有四个文本视图。其中三个文本视图具有较短的静态文本,但一个我正在以编程方式填充文本,并且该文本有时很长。 当文本长于约 2300 个字符时,父线性布局的背景消失。我不知道为什么?
我的视图定义:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:scrollbars="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/activity_background"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="@drawable/rounded_white"
android:orientation="vertical"
android:padding="16dp"
android:paddingBottom="30dp"
android:shadowColor="@color/black"
android:shadowDx="0"
android:shadowDy="0"
android:shadowRadius="5" >
Some stuff here...
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="@drawable/rounded_white"
android:orientation="vertical"
android:padding="16dp"
android:paddingBottom="30dp"
android:shadowColor="@color/black"
android:shadowDx="0"
android:shadowDy="0"
android:shadowRadius="5" >
Some stuff here...
</LinearLayout>
<LinearLayout
android:id="@+id/section_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="@drawable/rounded_white"
android:orientation="vertical"
android:padding="16dp"
android:paddingBottom="30dp"
android:shadowColor="@color/black"
android:shadowDx="0"
android:shadowDy="0"
android:shadowRadius="5" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="6dp"
android:gravity="left|center_vertical"
android:textColor="@color/dark_gray"
style="@style/TextLarge"
android:text="@string/description_header" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="@color/gray"
style="@style/TextSmall"
android:text="@string/from_wiki_monit" />
<TextView
android:id="@+id/description_content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:lineSpacingMultiplier="1.2"
android:textColor="@color/dark_gray"
style="@style/TextSmall" />
<TextView
android:id="@+id/description_source_url"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="@color/url_color"
android:linksClickable="true"
style="@style/TextSmall" />
</LinearLayout>
</LinearLayout>
</ScrollView>
ID 为“description_content”的文本视图是以编程方式填充的长视图。
和截图(抱歉链接,但我不能添加图片):
编辑: 感谢@Haresh 的回答,它给了我一些新的想法。我拿了一个大约 2380 个字符的文本,当我开始使用填充时,结果发现当我以 textview 高度更短的方式更改它时,背景就出现了。
所以看起来在 LinearLayout 的一些“固定”高度之后它缺少背景。
但我仍然不知道为什么会这样。
【问题讨论】:
-
尝试将第一个 LinearLayout 的高度设置为 match_parent
-
还是和match_parent一样:/
-
这里讨论了对这种行为的更好解释stackoverflow.com/questions/14519025/…
标签: android android-layout android-linearlayout textview