“match_parent”高度不适用于NestedScrollView内部的RelativeLayout

问题描述:

我在CoordinateLayout中使用View作为activity.xml中的根视图。在该XML中,我使用NestedScrollView并启用了appbar_scrolling_view_behavior。但是NestedScrollView内部的内容包装高度而不是匹配父项。“match_parent”高度不适用于NestedScrollView内部的RelativeLayout

这里是我的布局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> 

这里是布局预览enter image description here

+0

投入进度进行嵌套的滚动视图 –

+0

发生这种情况的侧NestedScrollView内的任何视图。我想我的布局匹配父,以便我可以相应地中心的意见 –

+0

发现的东西,检查此答案https://*.com/a/5225220 –

只添加NestedScrollView

android:fillViewport="true" 

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

为中心进度条添加版面重力 –