Skip to content Skip to sidebar Skip to footer

Android : Get View Only On Which Touch Was Released

I am in a tricky situation, hope you can help me with it. I have few views (TextViews), horizontally placed one after another in a linear layout. When I press on textview1, drag my

Solution 1:

You need to handle all your touch events in the LinearLayout and check the location of the child views (child.getLeft() and child.getRight()).

public boolean dispatchTouchEvent(MotionEvent event){
    int x = event.getX();
    int cc = getChildCount();
    for(int i = 0; i < cc; ++i){
        View c = getChildView();
        if(x > c.getLeft() && x < c.getRight()){
            return c.onTouchEvent(event);
        }
    }
    return false;
}

Post a Comment for "Android : Get View Only On Which Touch Was Released"