当LinearLayout包含长文本视图时,背景会消失。

3

我有一个问题。我有一个视图,其中包含几个垂直线性布局,它们都具有背景,在其中一个布局中有四个文本视图。其中三个文本视图具有简短的静态文本,但其中一个我使用编程方式填充文本,并且该文本有时相当长。

当文本长度超过约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”的文本视图是通过程序填充的长文本。

以下为截图(抱歉无法添加图片链接):

enter image description here

enter image description here

编辑: 感谢@Haresh的答案,它给了我一些新思路。我取了一个大约2380个字符的文本,当我开始调整填充时,发现当我以使文本视图高度较短的方式进行更改时,背景会出现。

因此,似乎在LinearLayout的某个“固定”高度之后,背景就消失了。

但是,我仍然不知道为什么会这样。


尝试将第一个LinearLayout的高度设置为match_parent。 - dharmendra
仍然与match_parent相同:/ - Arek_24
这种行为的更好解释在这里讨论:https://dev59.com/6G3Xa4cB1Zd3GeqPhKdL - boggy b
2个回答

0

很遗憾,这不是LinearLayout的问题。你的视图/布局对于Android渲染器来说太大了。请看我应用程序的日志(我也有同样的问题):

W/OpenGLRenderer﹕ Shape round rect too large to be rendered into a texture (436x6933, max=4096x4096)

新的硬件或软件配置有更高的限制。 我找到的唯一解决方案是在ViewonDraw()方法中绘制形状,这有时非常复杂(您需要绘制几个矩形、边框线+不同的方法来实现圆角)。

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>

谢谢回答,虽然没有解决问题,但是给了我一些思路。我已经更新了问题。 - Arek_24

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接