Android Scrollview嵌套FrameLayout嵌套RecyclerView 显示不全、滑动粘滞

标题可能说不清楚这么hehe的界面布局,如图(这里找来相似的界面布局 : 网易1元XX截图):java

绿色框选部分是ScrollView,红色框选部分是一个FrameLayout,里面放的是只有RecyclerView的Fragment,经过红色框选部分上面几个按钮切换Fragmentandroid

ScrollView:app

<ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scrollbars="none">

      <LinearLayout
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:orientation="vertical">
              <!-轮播、按钮等->
                  <FrameLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent">
                  </FrameLayout>
      </LinearLayout>
</ScrollView>

Fragment:布局

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

</android.support.v7.widget.RecyclerView>

开始我就是写成这样的,结果发现RecyclerView显示的不全spa

后来用解决嵌套难题很方便的NestedScrollView替代了ScrollViewcode

并引入 compile 'com.android.support:design:24.2.1'xml

添加 app:layout_behavior="@string/appbar_scrolling_view_behavior"utf-8

<android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        <!-这句是关键->
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        android:scrollbars="none">

      <LinearLayout
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:orientation="vertical">
              <!-轮播、按钮等->
                  <FrameLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent">
                  </FrameLayout>
      </LinearLayout>
</android.support.v4.widget.NestedScrollView>

滑动有粘滞的感受,此时,只要给RecyclerView设置:get

mRecyclerView.setNestedScrollingEnabled(false);

就行了。若是这些操做无效,那么试试升级依赖support包到23.2以上,或者更简单的方式使用RecyclerView/ListView...等添加头部string