Android——扩大ImageButton的点击区域

目标:扩大ImageButton的点击区域

 

遭遇问题:在布局文件xml中定义了一个ImageButton,因为图标尺寸很小导致很难有效点击。

     具体代码如下所示:

     

<ImageButton android:id="@+id/imageButtonAlbum"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/bt_album"
        android:contentDescription="@null"/>

     其点击区域如下图所示(蓝色边框选中区域):

                   

       因为可点击区域太小,导致很难点击到Button,体验非常不好。但是又不想扩大切片,也不想增加Java代码,如何做?

 

解决方案:具体代码如下

             

<ImageButton android:id="@+id/imageButtonAlbum"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="10dip"
        android:src="@drawable/bt_album"
        android:background="@null"
        android:contentDescription="@null"/>

     修改后效果图如下:

                  

 

结果:可准确并及时响应点击行为。达到目标。:)

 

有用资料推荐:http://www.apkbus.com/android-23885-1-1.html

资料内容提要:Android4.0规定的有效可触摸的UI元素标准是48dp,一般来说,48dp转化为一个物理尺寸,约为9毫米。建议的目标大小为7~10毫米,这一点与iPhone一致,这是一个用户手指能准确并且舒适触摸的区域。
       如图所示,你的UI元素可能小于48dp,图标仅有32dp,按钮仅有40dp,但是他们的实际可操作焦点都达到了48dp的大小。

       

             

 

posted @ 2012-08-11 16:27  Binary-Stream  阅读(5876)  评论(0编辑  收藏  举报