DevsmartLib-Android icon indicating copy to clipboard operation
DevsmartLib-Android copied to clipboard

View flickers when touching button and scrolled

Open raghulj opened this issue 13 years ago • 7 comments

The view is flickered when we hold the button and scroll. When any movement is made by tapping the button the view is flickering. Looks like problem in handling the touch event in the dispatchTouchEvent not sure though.

raghulj avatar Nov 16 '11 15:11 raghulj

I can confirm this bug

AEFeinstein avatar Dec 05 '11 04:12 AEFeinstein

Replacing dispatchTouchEvent with @Override public boolean onTouchEvent(MotionEvent event) { boolean handled = mGesture.onTouchEvent(event); return handled; } and

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    switch( ev.getActionMasked() ){
        case MotionEvent.ACTION_DOWN:
             mInitialX = ev.getX();
             mInitialY = ev.getY();             
             return false;
        case MotionEvent.ACTION_MOVE:
             float deltaX = Math.abs(ev.getX() - mInitialX);
             float deltaY = Math.abs(ev.getY() - mInitialY);
             return ( deltaX > 5 || deltaY > 5 );
        default:
             return super.onInterceptTouchEvent(ev);
    }
}

??

vrash avatar Feb 09 '12 18:02 vrash

I can confirm that the previous solution corrects the bug, thanks for that.

orgmir avatar Oct 25 '12 13:10 orgmir

@vrash your fix doesn't work properly. It causes big view jumps

httpdispatch avatar Dec 11 '12 08:12 httpdispatch

@httpdispatch well, @vrash fix is almost correct. It's working very good for me after I changed return false; to return true; in case ACTION_DOWN - so:

@Override
public boolean dispatchTouchEvent(final MotionEvent ev) {
    boolean handled = super.dispatchTouchEvent(ev);
    handled |= mGesture.onTouchEvent(ev);
    return handled;
}

@Override
public boolean onInterceptTouchEvent(final MotionEvent ev) {
    switch (ev.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
        mInitialX = ev.getX();
        mInitialY = ev.getY();
        //HERE RETURN TRUE INSTEAD OF FALSE
        return true;
    case MotionEvent.ACTION_MOVE:
        final float deltaX = Math.abs(ev.getX() - mInitialX);
        final float deltaY = Math.abs(ev.getY() - mInitialY);
        return deltaX > 5 || deltaY > 5;
    default:
        return super.onInterceptTouchEvent(ev);
    }
}

kamilzych avatar Jan 21 '13 12:01 kamilzych

Thanks @vrash, its solved my problem :)

DollyBansal avatar Feb 15 '13 21:02 DollyBansal

@kamilzych your approach also has issue. I am testing new one

    float mInitialX;
    float mInitialY;
    boolean mIsMoving;
    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        // experimental update to avoid view flickers and onclick events fired
        // after move
        boolean handled = mGesture.onTouchEvent(ev);
        switch (ev.getAction() & MotionEvent.ACTION_MASK) {
            case MotionEvent.ACTION_DOWN:
                mInitialX = ev.getX();
                mInitialY = ev.getY();
                mIsMoving = false;
                break;
            case MotionEvent.ACTION_MOVE: {
                final float deltaX = Math.abs(ev.getX() - mInitialX);
                final float deltaY = Math.abs(ev.getY() - mInitialY);
                mIsMoving = deltaX > 5 || deltaY > 5;
            }
                break;
        }
        if (!mIsMoving) {
            handled |= super.dispatchTouchEvent(ev);
        }
        return handled;
    }

It also has an issue that child component may not receive ACTION_UP event, but at least view should not flicker and on click works as expected

httpdispatch avatar Oct 25 '13 07:10 httpdispatch