Skip to content Skip to sidebar Skip to footer

Check If Dragged View Is Within The Bounds Of Another View

I am trying to create a floating layout similar to Facebook's messenger app, which has the Delete View which when dragged towards it. It will remove the Chat Bubble. But my proble

Solution 1:

Try this:

Rect outRect = newRect();
int[] location = newint[2];

Add this method

privatebooleanisViewInBounds(View view, int x, int y){
    view.getDrawingRect(outRect);
    view.getLocationOnScreen(location);
    outRect.offset(location[0], location[1]);
    return outRect.contains(x, y);
}

and add this to your ACTION_UP

case MotionEvent.ACTION_UP:
                    DeleteView.setVisibility(View.INVISIBLE);

                    if(isViewInBounds(DeleteView, x, y)){
                        DeleteView.dispatchTouchEvent(event);
                        Toast.makeText(FloatingViewService.this, "WITHIN", Toast.LENGTH_SHORT).show();
                    }
                    returntrue;

Post a Comment for "Check If Dragged View Is Within The Bounds Of Another View"