Increase active area for interface widgets to allow slightly out-of-bounds touches to count
Use android:padding attribute of view class in layout.xml
- android:padding attributes applies padding to all four edges of the widget and it is counted inside the widget.
- Hence touches slightly out of the widget will also be recorded.
- Use direction name to apply padding in any particular direction. e.g. android:paddingLeft.
- Use “dp” unit (density independent pixels) to target devices with different resolutions.
- The overall active area of the widget is shown in gray dashed border just for the demo purpose.
<ImageButton
android:id="@+id/active_area_ib_sqr_btn"
android:layout_width="wrap_content"
android:contentDescription="@string/active_area_image"
android:layout_height="wrap_content"
android:src="@drawable/ic_square_icon"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:padding="30dp"
android:background="@drawable/image_border"/>