Android expands the range of the click event receiving area
If there are some icons or ImageViews, these Views themselves are very small, so expand the receiving area of these events. Directly pass in the view that needs to expand the event receiving area, or you can customize how much size to expand. The default method is to add 20pix around the original View.
public static void expandTouchArea(View view) { setTouchDelegate(view, 20); } public static void expandTouchArea(View view, int size) { View parentView = (View) view.getParent(); parentView.post(new Runnable() { @Override public void run() { Rect rect = new Rect(); view.getHitRect(rect); rect.top -= size; rect.bottom += size; rect.left -= size; rect.right += size; parentView.setTouchDelegate(new TouchDelegate(rect, view)); } }); }