Android Scrollview嵌套RecycleView滑动不流畅,卡顿问题

最近在做项目时,需要仿QQ那样的弹性动画效果。于是就用ScrollView加RecycleView开始了。

<com.dten.assistant.ui.view.MyScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:color/white">
             <ImageView
                android:layout_below="@+id/ll_search"
                android:id="@+id/iv_line"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:scaleType="fitXY"
                android:src="@drawable/ic_content_line"
                android:layout_marginTop="10dp"
                android:layout_marginLeft="20dp"/>
            <android.support.v7.widget.RecyclerView
                android:layout_below="@+id/iv_line"
                android:id="@+id/rcv_selector_contents"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />

大概布局就是这样的,完成之后,发现一个问题,就是在滑动的不流畅,卡顿,基本就是手指移动多长,界面滑动多长距离。于是找资料,在recycleview添加这两个方法就可以了。

recyclerView.setHasFixedSize(true);
recyclerView.setNestedScrollingEnabled(false);

于是加上之后赶紧试了试,可是不对啊。。。。发现再向下滑动的时候划不动,这可怎么办呢。
原来我的布局是

<com.dten.assistant.ui.view.MyScrollView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

ScrollView是最外层的,于是在ScrollView外层再包裹一层布局即可

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#F9F9F9">
    <com.dten.assistant.ui.view.MyScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

现在就可以滑动了,而且很流畅,有滑动惯性。

另外:如果Listview或者RecycleView显示不全,只有一个itme,请在ScrollView中添加

android:fillViewport="true"

在Android 5.0后,滑动到底部或者顶部会有一个月牙形的影印,有些场景可能会有点不好看,去掉这个:

android:overScrollMode= "never"
android:fadingEdge="none"

欢迎大家批评指正。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值