1

I have a LinearLayout which appears in the middle of the screen and on above (zorder) my listview. This Linearlayout is composed by a few buttons.

I'd like that when I scroll on this LinearLayout it doesn't catch the event and let it go to the under list view. And when button are tapped that they get the onClick event.

I Hope this is clear...

1
  • In other words... The problem is that I have sticky view above a listview. This sticky view is composed with buttons that takes the whole sticky view. Do you have an idea to manage to pass the scrolling to the list view, and the click on buttons to buttons.. ?
    – gbero
    Commented Oct 11, 2013 at 12:48

1 Answer 1

0

For information, this is how I solved my problem. Hope the code is clear...

private Point p1;
private Point p2;
private int mTouchSlop;

public StickyView(Context context, AttributeSet attrs) {
    super(context, attrs);

    ViewConfiguration vc = ViewConfiguration.get(context);
    mTouchSlop = vc.getScaledTouchSlop();
}

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    if (ev.getAction() == MotionEvent.ACTION_UP || ev.getAction() == MotionEvent.ACTION_CANCEL) {
        listView.onTouchEvent(ev);
        return super.onInterceptTouchEvent(ev);
    } else if (ev.getAction() == MotionEvent.ACTION_MOVE) {
        p2 = new Point(0, (int) ev.getY());
        double distance = Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2));
        if (Math.abs(distance)> mTouchSlop) {
            listView.onTouchEvent(ev);
            return super.onInterceptTouchEvent(ev);
        }
        p1 = p2;
    } else if (ev.getAction() == MotionEvent.ACTION_DOWN) {
        p1 = new Point(0, (int) ev.getY());
        listView.onTouchEvent(ev);
    }
    return super.onInterceptTouchEvent(ev);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.