"match_parent" height is not working for RelativeLayout inside NestedScrollView
Asked Answered
V

2

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

Verditer answered 1/6, 2017 at 9:27 Comment(8)
put progressbar out side of nested scrollviewZacheryzack
This happens for any view inside NestedScrollView. I want my layout to match the parent , so that I can center the views accordinglyVerditer
found something , check this answer stackoverflow.com/a/5225220Zacheryzack
Tried this , but if we use a SnackBar or something it is overlapping with the hardware back button bar at the bottomVerditer
@SasankSunkavalli Have you tried by using only ScrollView ?Dielle
Try to use android:layout_alignParentBottom="true" as well as android:layout_alignParentTop="true" in nested scrollview.Reconcile
@jaydroider ScrollView child cant match the parent right ?Verditer
@SasankSunkavalli It's main child will wrap the whole content.Dielle
W
48

just add in NestedScrollView

 android:fillViewport="true"
Watch answered 1/6, 2017 at 9:40 Comment(1)
Works Perfect!!Neoplasticism
A
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>
Aureomycin answered 3/6, 2017 at 8:37 Comment(1)
add layout gravity for center progress barAureomycin

© 2022 - 2024 — McMap. All rights reserved.