首页 > 解决方案 > 为什么TextView不显示?

问题描述

我的带有 TextView 的 LinearLayout 未在片段布局中显示。不显示带有 ImageView 的 LinearLayout 下的 Content。

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#fff">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:padding="20dp">

        <!-- Other content -->

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

<!--
This TextView is not displayed
-->        

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="DUMMY"/>

    </LinearLayout>

</ScrollView>

标签: androidxml

解决方案


使用ScrollView时只能生一个孩子。

所以你的观点必须是这样的

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#fff">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        >

         <!-- Your content -->

    </LinearLayout>

</ScrollView>

你的内容在这里

 <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:padding="20dp">

        <!-- Other content -->

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

<!--
This TextView is not displayed
-->        

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="DUMMY"/>

    </LinearLayout>

推荐阅读