标题可能说不清楚这么hehe的界面布局,如图(这里找来类似的界面布局 : 网易1元XX截图):
绿色框选部分是ScrollView,红色框选部分是一个FrameLayout,里面放的是只有RecyclerView的Fragment,通过红色框选部分上面几个按钮切换Fragment
ScrollView:
<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显示的不全
后来用解决嵌套难题很方便的NestedScrollView替代了ScrollView
并引入 compile 'com.android.support:design:24.2.1'
添加 app:layout_behavior="@string/appbar_scrolling_view_behavior"
<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设置:
mRecyclerView.setNestedScrollingEnabled(false);
就好了。如果这些操作无效,那么试试升级依赖support包到23.2以上,或者更简单的方式使用RecyclerView/ListView...等添加头部