Tutorialwork
Tutorialwork

Reputation: 73

Why is TextView not displayed?

My LinearLayout with a TextView is not showing in a fragment layout. The Content under the LinearLayout with the ImageView is not displayed.

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

Upvotes: 1

Views: 81

Answers (3)

Javad Shakouri
Javad Shakouri

Reputation: 129

You can not have two layers in the scroll view The scroll visually embeds a layer inside and the other layers are inside it

you can use sample

<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="vertical">

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



    </LinearLayout>

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

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

    </LinearLayout>

</LinearLayout>

Upvotes: 0

Radesh
Radesh

Reputation: 13555

When you use ScrollView you can have only one child.

So your view must something like this

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

Here Your content is

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

Upvotes: 2

Chrisvin Jem
Chrisvin Jem

Reputation: 4060

You can't have multiple LinearLayouts in ScrollView. Try wrapping them inside a single LinearLayout. Something along the following lines should work,

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

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

            <!-- Other content -->

        </LinearLayout>

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

    </LinearLayout>
</ScrollView>

Upvotes: 0

Related Questions