zoukankan      html  css  js  c++  java
  • 子控件调用 requestDisallowInterceptTouchEvent(true) 无效 #906

     

     Closed
     
     
    chiemy opened this issue on 16 May 2019 · 5 comments
     
     Closed
     
     

    子控件调用 requestDisallowInterceptTouchEvent(true) 无效#906

    chiemy opened this issue on 16 May 2019 · 5 comments
     

    Comments

    @chiemy
     
     

    chiemy commented on 16 May 2019 • 

    edited 

    自定义了一个控件,在 onTouchEvent 的 ACTION_DOWN 事件里调用 requestDisallowInterceptTouchEvent(true),事件还是被拦截了,使用官方 SwipeRefreshLayout 则没有这个问题

     
     
    @chiemy chiemy changed the title 子控件调用 requestDisallowInterceptTouchEvent(true) 还是会被拦截 子控件调用 requestDisallowInterceptTouchEvent(true) 无效 on 16 May 2019
    @scwang90
     
    Owner

    scwang90 commented on 25 May 2019

    能提供一下你的应用场景吗?给一个demo 代码,可以更高更快的解决这个问题。

    @hoop208
     
     

    hoop208 commented on 14 Aug 2019 • 

    edited 

    有这样一个场景:SmartRefreshLayout里面的内容需要支持长按后绘制当前手指移动的坐标(比如股票的分时图折线图).调用requestDisallowInterceptTouchEvent(true)只是设置了mGroupFlags的标记位.SmartRefreshLayout在重写dispatchTouchEvent的时候好像没有对mGroupFlags |= FLAG_DISALLOW_INTERCEPT的情况做处理.

    布局文件:

    <TextView
        android:layout_width="match_parent"
        android:text="需求是内容控件长按后显示当前手指移动的坐标,比如股票分时k线图"
        android:layout_height="wrap_content" />
    
    <com.scwang.smartrefresh.layout.SmartRefreshLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <com.scwang.refreshlayout.activity.MoveView
            android:layout_width="match_parent"
            android:background="#33000000"
            android:layout_height="match_parent" />
    
    </com.scwang.smartrefresh.layout.SmartRefreshLayout>
    

    长按后需要绘制坐标的控件:

    public class MoveView extends AppCompatTextView {
    
    
        //移动的阈值
        private static final int TOUCH_SLOP = 20;
        /**
         * 点击按下事件 X坐标记录
         */
        private float mLastMotionX;
        /**
         * 点击按下事件 Y坐标记录
         */
        private float mLastMotionY;
    
        private boolean mDelay;
    
        /**
         * 长按模式的标记位
         */
        private boolean isLongPress;
    
        /**
         * 长按的runnable
         */
        private Runnable mLongPressRunnable = new Runnable() {
            @Override
            public void run() {
                isLongPress = true;
                mDelay = false;
                getParent().requestDisallowInterceptTouchEvent(true);
            }
        };
    
        public MoveView(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
    
        @Override
        public boolean onTouchEvent(MotionEvent event) {
            float x = event.getX();
            float y = event.getY();
    
            switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    mLastMotionX = x;
                    mLastMotionY = y;
                    postDelayed(mLongPressRunnable, ViewConfiguration.getLongPressTimeout());
                    mDelay = true;
                    break;
                case MotionEvent.ACTION_MOVE:
                    if (isLongPress) {
                        //长按状态下.绘制时间和轴线
                        setText("x=" + x + ";y=" + y);
                    } else if (mDelay && (Math.abs(mLastMotionX - x) > TOUCH_SLOP
                            || Math.abs(mLastMotionY - y) > TOUCH_SLOP)) {
                        //移动超过阈值,则表示移动了
                        removeCallbacks(mLongPressRunnable);
                        mDelay = false;
                    }
                    break;
                case MotionEvent.ACTION_UP:
                case MotionEvent.ACTION_CANCEL:
                default:
                    //释放了
                    removeCallbacks(mLongPressRunnable);
                    isLongPress = false;
                    mDelay = false;
                    invalidate();
                    break;
            }
            return true;
        }
    
    }
    
     
    @WoKee
     
     

    WoKee commented on 25 May 2020

    if (mSuperDispatchTouchEvent) {//如果父类拦截了事件,发送一个取消事件通知
    e.setAction(MotionEvent.ACTION_CANCEL);
    super.dispatchTouchEvent(e);
    }
    应该是直接发了一个取消事件通知导致的

     
    @scwang90
     
    Owner

    scwang90 commented on 27 May 2020

    添加 android:nestedScrollingEnabled="true" 即可

    <com.scwang.smartrefresh.layout.SmartRefreshLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <com.scwang.refreshlayout.activity.MoveView
            android:layout_width="match_parent"
            android:background="#33000000"
            android:layout_height="match_parent" 
            android:nestedScrollingEnabled="true"/>
    
    </com.scwang.smartrefresh.layout.SmartRefreshLayout>
    
     
    @scwang90 scwang90 closed this on 27 May 2020
     
    @WoKee
     
     

    WoKee commented on 27 May 2020

    <ViewFlipper
    android:id="@+id/vf_top_post"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:flipInterval="7000"
    android:layout_marginStart="16dp"
    android:layout_marginEnd="16dp"
    android:layout_marginBottom="16dp"
    android:nestedScrollingEnabled="true"
    android:background="@drawable/find_viewflipper_bg"
    android:inAnimation="@anim/push_down_in"
    android:outAnimation="@anim/push_down_out" />

    recyclerview 使用 BaseQuickAdapter.addFooterView(ViewFlipper) ;
    android:nestedScrollingEnabled无效,当数据不满一页是,触摸ViewFlipper滚动,会触发下拉刷新

     
     
     
    https://github.com/scwang90/SmartRefreshLayout/issues/906
  • 相关阅读:
    C# 实现任务栏图标程序
    C#实现的木马之客户端
    sql基本语法
    水晶报表引用DataSet做数据源
    解决多线程操作控件时可能出现的异常:“在某个线程上创建的控件不能成为在另一个线程上创建的控件的父级”
    电子书籍制作工具软件大全
    C#实现的木马之服务端
    2进制、8进制、10进制、16进制...各种进制间的轻松转换
    VC# .Net中使用Crystal Report水晶报表
    P2P技术学习
  • 原文地址:https://www.cnblogs.com/pengmn/p/15393159.html
Copyright © 2011-2022 走看看