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

相關文章
相關標籤/搜索