zoukankan      html  css  js  c++  java
  • Android中禁止SlidingPaneLayout的侧滑功能

    Android中使用android.support.v4.widget.SlidingPaneLayout实现侧滑功能的时候,可能出现滑动屏幕时与SlidingPaneLayout的侧滑发生冲突,查看了帮助文档,发现并没有提供禁止侧滑的方法,所以不得不继承SlidingPanelLayout重写它的方法。直接上代码:

    <span style="font-size:14px;">
    
    <span style="font-size:14px;"><span style="font-size:14px;">
    import android.content.Context;
    import android.support.v4.view.MotionEventCompat;
    import android.support.v4.widget.SlidingPaneLayout;
    import android.util.AttributeSet;
    import android.view.MotionEvent;
    
    /**
     * Created by long on 2016/3/29.
     */
    public class PagerEnabledSlidingPaneLayout extends SlidingPaneLayout {
    
        //是否禁止侧滑
        private boolean prohibitSideslip = false;
    
        public PagerEnabledSlidingPaneLayout(Context context){
            super(context, null);
        }
        public PagerEnabledSlidingPaneLayout(Context context,AttributeSet attrs){
            super(context, attrs, 0);
        }
        public PagerEnabledSlidingPaneLayout(Context context,AttributeSet attrs,int defStyle){
            super(context, attrs, defStyle);
        }
    
        public boolean getProhibitSideslip(){
            return prohibitSideslip;
        }
        //在需要禁止或允许侧滑的地方调用该方法
        public void setProhibitSideslip(boolean prohibitSideslip){
            this.prohibitSideslip = prohibitSideslip;
        }
    
        //该方法可以拦截SlidingPaneLayout的触屏事件
        @Override
        public boolean onInterceptTouchEvent(MotionEvent ev) {
            switch (MotionEventCompat.getActionMasked(ev)){
                case MotionEvent.ACTION_MOVE:
                    if(prohibitSideslip){
                        return false;
                    }
            }
            return super.onInterceptTouchEvent(ev);
        }
    
        @Override
        public boolean onTouchEvent(MotionEvent ev) {
            switch (MotionEventCompat.getActionMasked(ev)){
                case MotionEvent.ACTION_MOVE:
                    if(prohibitSideslip){
                        return false;
                    }
            }
            return super.onTouchEvent(ev);
        }
    
    
    } </span>
    
    
    </span>



    参考:http://www.cnblogs.com/apaojun/p/4288483.html

    关注公众号,分享干货,讨论技术


  • 相关阅读:
    JVM内存区域类别
    ConcurrentHashMap初探
    一张图理解RACSignal的Subscription过程
    ObjC的Block中使用weakSelf/strongSelf @weakify/@strongify
    自己写简单CoreDataManager封装对CoreData操作
    [转]layoutSubviews总结
    [转]日期格式化(yyyy-MM-dd)中,为什么 M 多大写?
    Native App执行JS
    Mac下配置Maven
    Mac OS X中配置Apache
  • 原文地址:https://www.cnblogs.com/molashaonian/p/9097651.html
Copyright © 2011-2022 走看看