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

标题可能说不清楚这么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...等添加头部

转载于:https://my.oschina.net/yaly/blog/810324

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值