I have a button with a custom drawable.
<Button android:layout_width="22dip" android:layout_height="23dip" android:background="@drawable/triangle" />
The drawable is a triangle with transparent background.
|\ | \ |__\
I find this button hard to tap. First, it's relatively small. Second, the transparent pixels are not tappable. I would like to keep the drawable the same size, but make the hit area a square shape twice the size of the triangle.
_____________ | | | |\ | | | \ | | |__\ | |____________|
Tap the Gear icon that appears at the top of the Android keyboard. Open Preferences. Tap the Keyboard Height option. You'll see seven different options ranging from "Extra-short" to "Extra-tall." The default is "Normal." Tap the option you prefer.
We can set custom shapes on our button using the xml tag <shape> . These xml files are created in the drawable folder too. shape can be used inside selectors . The shape can be set to rectangle (default), oval , ring , line .
you can use TouchDelegate API.
final View parent = (View) button.getParent(); // button: the view you want to enlarge hit area parent.post( new Runnable() { public void run() { final Rect rect = new Rect(); button.getHitRect(rect); rect.top -= 100; // increase top hit area rect.left -= 100; // increase left hit area rect.bottom += 100; // increase bottom hit area rect.right += 100; // increase right hit area parent.setTouchDelegate( new TouchDelegate( rect , button)); } });
You want "padding" It will put the space inside the view. Margin will put the space outside, which will not increase the hit area.
<Button android:layout_width="22dip" android:layout_height="23dip" android:background="@drawable/triangle" android:padding="10dp" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With