Frage

I made following adjustment to my custom ViewGroups dispatchTouchEvent.

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    final float xf = ev.getX();
    final float yf = ev.getY();
    final float scrolledXFloat = xf + getScrollX();
    final float scrolledYFloat = yf + getScrollY();
    final int scrolledXInt = (int) scrolledXFloat;
    final int scrolledYInt = (int) scrolledYFloat;

    if(isDetailOpened()){
        mDetailView.getHitRect(mTempRect);
        if(mTempRect.contains(scrolledXInt,scrolledYInt)){
            // offset the event to the view's coordinate system
            final float xc = scrolledXFloat - mDetailView.getLeft();
            final float yc = scrolledYFloat - mDetailView.getTop();
            MotionEvent cp = MotionEvent.obtain(ev);
            cp.setLocation(xc, yc);
            boolean consumed = mDetailView.dispatchTouchEvent(cp);
            cp.recycle();
            return consumed;
        }
    }

    return super.dispatchTouchEvent(ev);
}

mDetailView gets events in his onTouchEvent, but does not fire onClickListener properly, but GestureDetector for example works fine. Anyone has an idea what may be causing this? mDetailView is not part of view hierarchy. I am drawing it manually in dispatchDraw. Maybe not having View attached to window could be a problem. Any information regarding this? Thanks

War es hilfreich?

Lösung

Problem was not having my detail view inserted in ViewGroup. When mDetailView became child of my custom ViewGroup, problem was solved.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top