如何增加Android的按钮点击区域无缩放背景是什么? [英] How to increase hit area of Android button without scaling background?

查看:123
本文介绍了如何增加Android的按钮点击区域无缩放背景是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义绘制一个按钮。

 <按钮
    机器人:layout_width =22dip
    机器人:layout_height =23dip
    机器人:背景=@可绘制/三角/>
 

的绘制是透明背景的三角形。

  | \
| \
| __ \
 

我觉得这个按钮很难挖掘。首先,它是相对较小的。其次,在透明像素不是tappable。我想保持绘制相同的大小,但使灾区方形两次三角形的大小。

  _____________
| |
| | \ |
| | \ |
| | __ \ |
| ____________ |
 

解决方案

您想要的填充它会把空间视图中。保证金将会把空间外,这不会增加灾区。

 <按钮
    机器人:layout_width =22dip
    机器人:layout_height =23dip
    机器人:背景=@可绘制/三角
    机器人:填充=10dp/>
 

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.

_____________
|            |
|    |\      |
|    | \     |
|    |__\    |
|____________|

解决方案

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" />

这篇关于如何增加Android的按钮点击区域无缩放背景是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆