解决5.0以上系统ScrollView嵌套RecyclerView滑动迟缓

来源:互联网 发布:文本语音朗读软件 编辑:程序博客网 时间:2024/04/28 13:40

不多说了,上代码

方法一:自定义控件,但是可能会遇到RecyclerView显示不全

import android.content.Context;import android.util.AttributeSet;import android.view.MotionEvent;import android.view.ViewConfiguration;import android.widget.ScrollView;/** * ----------Dragon be here!----------/ *    ┏┓   ┏┓ *   ┏┛┻━━━┛┻┓ *   ┃       ┃ *   ┃   ━   ┃ *   ┃ ┳┛ ┗┳ ┃ *   ┃       ┃ *   ┃   ┻   ┃ *   ┃       ┃ *   ┗━┓   ┏━┛ *     ┃   ┃神兽保佑 *     ┃   ┃代码无BUG! *     ┃   ┗━━━┓ *     ┃       ┣┓ *     ┃       ┏┛ *     ┗┓┓┏━┳┓┏┛ *      ┃┫┫ ┃┫┫ *      ┗┻┛ ┗┻┛ * ━━━━━━神兽出没━━━━━━ * * @author Reginer on  2016/5/29 19:06. *         Description:解决5.0以上系统ScrollView嵌套RecyclerView滑动迟缓 */public class SpeedScrollView extends ScrollView {//    private int downX;    private int downY;    private int mTouchSlop;    public SpeedScrollView(Context context) {        super(context);        mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();    }    public SpeedScrollView(Context context, AttributeSet attrs) {        super(context, attrs);        mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();    }    public SpeedScrollView(Context context, AttributeSet attrs, int defStyleAttr) {        super(context, attrs, defStyleAttr);        mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();    }    @Override    public boolean onInterceptTouchEvent(MotionEvent e) {        int action = e.getAction();        switch (action) {            case MotionEvent.ACTION_DOWN://                downX = (int) e.getRawX();                downY = (int) e.getRawY();                break;            case MotionEvent.ACTION_MOVE:                int moveY = (int) e.getRawY();                if (Math.abs(moveY - downY) > mTouchSlop) {                    return true;                }        }        return super.onInterceptTouchEvent(e);    }}

xml里使用这个自定义的ScrollView就可以了。

方法二:
可以使用android.support.v4.widget.NestedScrollView控件,然后
mRecyclerView.setNestedScrollingEnabled(false);
mRecyclerView.setHasFixedSize(false);

0 0
原创粉丝点击