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

  • 相关阅读:
    Maven错误recv failed
    eclipse集成tomcat修改字符集参数
    eclipse luna 无法安装veloeclipse问题
    TortoiseSVN忽略文件夹
    类之特性
    __new()__与__init__()
    flask中models设计
    flask读书记录
    JS中的event 对象详解
    redis 持久化 RDB
  • 原文地址:https://www.cnblogs.com/molashaonian/p/7445861.html
Copyright © 2011-2022 走看看