5

I am using CoordinatorLayout as my root View in activity.xml. In that xml , I am using NestedScrollView with appbar_scrolling_view_behavior enabled. But the content inside the NestedScrollView is wrapping the height instead of Matching the Parent.

Here is my layout xml

<?xml version="1.0" encoding="utf-8"?>
 <android.support.design.widget.CoordinatorLayout
  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"
  android:background="@android:color/white">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.v7.widget.Toolbar
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_scrollFlags="scroll|enterAlways|snap">
    </android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <ProgressBar
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/content"
            android:padding="20dp"
            android:visibility="gone"/>
    </RelativeLayout>


  </android.support.v4.widget.NestedScrollView>


</android.support.design.widget.CoordinatorLayout>

Here is the layout preview enter image description here

Sasank Sunkavalli
  • 3,864
  • 5
  • 31
  • 55

2 Answers2

48

just add in NestedScrollView

 android:fillViewport="true"
Jai Khambhayta
  • 4,198
  • 2
  • 22
  • 29
0
 <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center">

        <ProgressBar
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="20dp"
            android:text="content"
            android:visibility="visible" />
    </RelativeLayout>