View myView = findViewById(R.id.my_view); Rect rect = new Rect(); myView.getHitRect(rect); Log.d(TAG, "Hit rectangle: " + rect.toString());
Button myButton = findViewById(R.id.my_button); Rect rect = new Rect(); myButton.getHitRect(rect); rect.inset(-10, -10); TouchDelegate touchDelegate = new TouchDelegate(rect, myButton); ((View) myButton.getParent()).setTouchDelegate(touchDelegate);In this example, we create a larger touch area for a button by expanding its hit rectangle using the Rect.inset() method, and then attach a TouchDelegate to the button's parent view. This method belongs to the android.view.View package library.