SlidingMenu和Listview冲突解决方案

SlidingMenu和Listview冲突解决方案

前些日子做了一个项目用到了仿QQ侧滑效果,然后就在我的男神博客里找到了这篇文章。用上之后效果确实不错,但是bug也随之出现,一但主页面中有Listview就会和项目中的HorizontalScrollView发生冲突,鸿洋大神并没有给出解决方案,下方大家的评论也都没给出,没办法只能自己研究了。最后终于让我找到了解决方案。

解决方案:重写HorizontalScrollView,然后替换掉重写HorizontalScrollView,然后滑起来就比较顺畅了。代码如下:

/**
 * @author 作者 YYD
 * @version 创建时间:2016年7月24日 上午7:57:05
 * @function 未添加
 */
public class CustomHorizontalScrollView extends HorizontalScrollView {  

    float lastX, lastY;  

    private GestureDetector mGestureDetector;  
    View.OnTouchListener mGestureListener;  

    public CustomHorizontalScrollView(Context context) {  
        super(context);  
        mGestureDetector = new GestureDetector(context, new YScrollDetector());  
        setFadingEdgeLength(0);  
    }  

    public CustomHorizontalScrollView(Context context, AttributeSet attrs) {  
        super(context, attrs);  
        mGestureDetector = new GestureDetector(context, new YScrollDetector());  
        setFadingEdgeLength(0);  
    }  

    public CustomHorizontalScrollView(Context context, AttributeSet attrs, int defStyleAttr) {  
        super(context, attrs, defStyleAttr);  
        mGestureDetector = new GestureDetector(context, new YScrollDetector());  
        setFadingEdgeLength(0);  
    }  

    @Override  
    public boolean onInterceptTouchEvent(MotionEvent ev) {  
        return super.onInterceptTouchEvent(ev) && mGestureDetector.onTouchEvent(ev);  
    }  

    /**  
     * 如果竖向滑动距离<横向距离,执行横向滑动,否则竖向。如果是ScrollView,则'<'换成'>'  
     */  
    class YScrollDetector extends GestureDetector.SimpleOnGestureListener {  
        @Override  
        public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {  
            if (Math.abs(distanceY) < Math.abs(distanceX)) {  
                return true;  
            }  
            return false;  
        }  
    }  
}  

最后 奉送上代码,希望对大家有所帮助,兄弟手头紧张,小收1分资源费,如果大家不想用分,完全可以按照上面我说的方式自己弄,不用下载,请见谅!

评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

程序编织梦想

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值