我有问题。我有一个几乎没有垂直线性布局的视图,所有这些都有背景,其中一个有四个文本视图。其中三个文本视图有简短的静态文本,但是我用编程方式填充文本,这个文本有时很长。 当文本长于~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>
Textview with id&#34; description_content&#34;是以编程方式填写的长文本。
截图(对不起链接但我无法添加图片):
修改 感谢@Haresh的回答,它给了我一些新的想法。我拿了一个带有~2380个字符的文本,当我开始使用填充时,事实证明当我以textview高度更短的方式更改它时,背景就出现了。
所以看起来像是在修复了一些&#39; LinearLayout的高度缺少背景。
但我仍然不知道为什么会发生这种情况。
答案 0 :(得分:0)
// Try this way,hope this will help you to solve your problem...
<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"
android:padding="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="30dp"
android:background="@drawable/rounded_white"
android:orientation="vertical"
android:padding="10dp"
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_marginBottom="10dp"
android:background="@drawable/rounded_white"
android:orientation="vertical"
android:padding="10dp"
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_marginBottom="10dp"
android:background="@drawable/rounded_white"
android:orientation="vertical"
android:padding="10dp"
android:shadowColor="@color/black"
android:shadowDx="0"
android:shadowDy="0"
android:shadowRadius="5" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:textColor="@color/dark_gray"
style="@style/TextLarge"
android:text="@string/description_header" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/gray"
style="@style/TextSmall"
android:layout_marginBottom="5dp"
android:text="@string/from_wiki_monit" />
<TextView
android:id="@+id/description_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:lineSpacingMultiplier="1.2"
android:textColor="@color/dark_gray"
style="@style/TextSmall" />
<TextView
android:id="@+id/description_source_url"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/url_color"
android:layout_marginBottom="5dp"
android:linksClickable="true"
style="@style/TextSmall" />
</LinearLayout>
</LinearLayout>
</ScrollView>
答案 1 :(得分:0)