Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"match_parent" height is not working for RelativeLayout inside NestedScrollView

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

like image 778
Sasank Sunkavalli Avatar asked Jun 01 '17 09:06

Sasank Sunkavalli


People also ask

How to add a linearlayout inside a nestedscrollview?

Add the NestedScrollView and inside NestedScrollView add a LinearLayout and inside LinearLayout add two TextView to display the strings which are created inside the strings.xml file and one Button between the TextView. Here is the code for the activity_main.xml file. One can add as many views inside the NestedScrollView’s LinearLayout

What is nestedscrollview in Android?

Last Updated : 18 Feb, 2021 NestedScrollView is just like ScrollView, but it supports acting as both a nested scrolling parent and child on both new and old versions of Android. It is enabled by default. NestedScrollView is used when there is a need for a scrolling view inside another scrolling view.

Why is pull-up Refresh not working in nextedscrollview?

As NextedScrollView won't let recycle the items of RecyclerView & loads all the items in one shot, pull-up refresh won't work. We need to manually/listen-to monitor the NestedScrollView's scrolling event & do the load-more-items thing in child's RecyclerView.

Can a ScrollView scroll through a linear layout?

If the linearlayout has a height of wrap_content then the height is not related to the height of the screen and the scrollview will be able to scroll through it. Just remember that a scrollview can only have 1 direct child, and that child needs android:layout_height="wrap_content"


1 Answers

just add in NestedScrollView

 android:fillViewport="true"
like image 185
jai khambhayta Avatar answered Sep 21 '22 11:09

jai khambhayta