'Why LinearLayout within ScrollView is hidden?

I added a LinearLayout within ScrollView and it is hidden when running the app. This is the XML.

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <ScrollView
        android:id="@+id/scrollview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/transparent">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="@dimen/unit_128">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_above="@+id/login_title"
                android:layout_marginBottom="@dimen/_16sdp"
                android:gravity="center">

                <ImageView
                    android:id="@+id/learn_more_icon"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/ic_paper" />

                <TextView
                    android:id="@+id/learn_more"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginHorizontal="@dimen/_8sdp"
                    android:fontFamily="@font/work_sans"
                    android:text="@string/fsa_regulated_learn_more"
                    android:textColor="@color/white" />
            </LinearLayout>

            <TextView
                android:id="@+id/login_title"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="@dimen/unit_16"
                android:layout_marginTop="@dimen/unit_32"
                android:layout_marginEnd="@dimen/unit_16"
                android:fontFamily="@font/work_sans"
                android:gravity="center"
                android:text="@string/sign_in_to_get_started"
                android:textColor="@color/white"
                android:textSize="@dimen/_14sp" />


            <EditText
                android:id="@+id/email_edt"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/login_title"
                android:layout_marginStart="@dimen/unit_16"
                android:layout_marginTop="@dimen/unit_24"
                android:layout_marginEnd="@dimen/unit_16"
                android:background="@drawable/border_btn"
                android:drawableStart="@drawable/ic_icon_user"
                android:drawablePadding="@dimen/_8sdp"
                android:fontFamily="@font/work_sans_medium"
                android:hint="@string/email"
                android:inputType="textEmailAddress"
                android:padding="@dimen/unit_12"
                android:singleLine="true"
                android:text="@={viewModel.emailObservable}"
                android:textColor="@color/white"
                android:textColorHint="#707070"
                android:textSize="@dimen/_15sp"
                app:error="@{viewModel.errEmailObservable}" />


            <EditText
                android:id="@+id/password_edt"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/email_edt"
                android:layout_marginStart="@dimen/unit_16"
                android:layout_marginTop="@dimen/unit_16"
                android:layout_marginEnd="@dimen/unit_16"
                android:background="@drawable/border_btn"
                android:drawableStart="@drawable/ic_password"
                android:drawablePadding="@dimen/_8sdp"
                android:fontFamily="@font/work_sans"
                android:hint="@string/password"
                android:inputType="textPassword"
                android:padding="@dimen/unit_12"
                android:singleLine="true"
                android:text="@={viewModel.passwordObservable}"
                android:textColor="@color/white"
                android:textColorHint="#707070"
                android:textSize="@dimen/_15sp"
                app:error="@{viewModel.errPasswordObservable}" />

            <TextView
                android:id="@+id/error"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/password_edt"
                android:layout_marginStart="@dimen/unit_16"
                android:layout_marginTop="@dimen/unit_8"
                android:layout_marginEnd="@dimen/unit_16"
                android:fontFamily="@font/work_sans"
                android:gravity="start"
                android:paddingStart="@dimen/_8sdp"
                android:paddingEnd="@dimen/_8sdp"
                android:text="@={viewModel.generalErrorObservable}"
                android:textColor="@color/red"
                android:textSize="@dimen/_12sp"
                android:visibility='@{viewModel.generalErrorObservable.empty? View.GONE : View.VISIBLE}' />

            <Button
                android:id="@+id/submit_btn"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/error"
                android:layout_centerVertical="true"
                android:layout_marginStart="@dimen/unit_16"
                android:layout_marginTop="@dimen/unit_16"
                android:layout_marginEnd="@dimen/unit_16"
                android:background="@drawable/rounder_btn"
                android:backgroundTint="@{viewModel.lockedAccountErrorObservable ? @color/selected_bottom_color : @color/green}"
                android:enabled="@{!viewModel.lockedAccountErrorObservable}"
                android:onClick="@{() -> viewModel.submitLoginPress()}"
                android:padding="@dimen/unit_8"
                android:text="@string/login"
                android:textColor="@color/white"
                android:textSize="@dimen/_18sp" />

            <TextView
                android:id="@+id/forgot_password"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/submit_btn"
                android:layout_marginStart="@dimen/unit_16"
                android:layout_marginTop="@dimen/unit_16"
                android:layout_marginEnd="@dimen/unit_16"
                android:layout_marginBottom="@dimen/unit_64"
                android:fontFamily="@font/work_sans"
                android:gravity="center"
                android:onClick="@{() -> viewModel.forgetPasswordPress()}"
                android:text="@string/forgot_password"
                android:textColor="@color/white"
                android:textSize="@dimen/_14sp" />

        </RelativeLayout>

    </ScrollView>


</layout>

Why LinearLayout is hidden and how to show it here? thank you



Solution 1:[1]

I try your code, It seems fine. When I call on fragment like below, It works.

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".FirstFragment">


        <include layout="@layout/yourLayout"/>

</androidx.constraintlayout.widget.ConstraintLayout>

Maybe you are doing wrong on <include layout . Because, your current XML layout seems fine.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 harun karaca