增加按钮的可点击区域 [英] Increase the clickable area of the button

查看:106
本文介绍了增加按钮的可点击区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想增加按钮的可点击区域。但是按钮中的图像应保持相同大小。我也将图像设置为背景而不是背景。

I want to increase the clickable area of the button.But the image in the button should remain of same size.Also i have set image as a background not as source .How can i do that?

 <Button
        android:id="@+id/backbutton"
        android:layout_width="25dp"
        android:layout_height="25dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="15dp"
        android:layout_marginTop="5dp"
        android:background="@drawable/arrow"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"

        android:textColor="@color/title_gray"
        android:textSize="14sp"


        android:visibility="visible" />


推荐答案

只需将按钮的父级布局(较大大小或可点击大小),然后执行类似的点击事件-

Just make the parent layout of the button (of larger size or clickable size), and perform click event of that like -

<LinearLayout
 android:id="@+id/backbuttonlayout"
        android:layout_width="50dp"
        android:layout_height="50dp">
<Button
        android:id="@+id/backbutton"
        android:layout_width="25dp"
        android:layout_height="25dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="15dp"
        android:layout_marginTop="5dp"
        android:background="@drawable/arrow"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"

        android:textColor="@color/title_gray"
        android:textSize="14sp"


        android:visibility="visible" />
</LinearLayout>

现在,在您的活动中,执行--

Now, inside your activity, do like -

LinearLayout backbuttonlayout = (LinearLayout)findViewById(R.id.backbuttonlayout);

并在backbuttonlayout上执行setOnClickListener()

and perform setOnClickListener() on backbuttonlayout

这篇关于增加按钮的可点击区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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