我可以增加一个按钮的onclick面积编程? [英] Can I increase a buttons onclick-area programmatically?

查看:137
本文介绍了我可以增加一个按钮的onclick面积编程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时候,我有我的用户界面的一个按钮,它是如此之小,这是很难点击。我的解决方案迄今已在Photoshop中添加一个透明的边框环绕按钮。只是增加按钮上的填充不工作,因为这也将拉伸图像。既然是一种小题大做,以我想改变点击面,每次打开Photoshop中,有没有办法以编程方式做到这一点?我试图使按钮后面的FrameLayout,并使其点击,但随后的按钮不会更改外观在触摸,因为它应该。 Ofcourse我还可以添加上改变按钮外观的FrameLayout一个ontouchlistener,但随后相当长的一段code,如果我有几个这些按钮。

Sometimes I have a button in my UI that it is so small that it is difficult to click. My solution so far has been to add a transparent border around the button in photoshop. Just increasing the padding on the button does not work, since this will also stretch the image. Since it is kind of a fuss to open photoshop each time I want to change the clickable surface, is there any way to do this programmatically? I have tried placing a framelayout behind the button and make it clickable, but then the button wont change appearance on touch as it should. Ofcourse I could also add a ontouchlistener on the framelayout which changes the buttons appearance, but then it quite some code if I have several of those buttons.

干杯,

推荐答案

我刚刚发现了一个巧妙的方法来解决这个问题。

I have just found a neat way to solve this problem.

  1. 环绕按钮与一个说的LinearLayout具有填充圆形按钮。
  2. 的onclick到的LinearLayout添加相同的按钮。
  3. 在按键设置duplicateParentState为true这使得当你点击该按钮外部,但里面的LinearLayout的按钮突出。

  1. Surround the button with a say a LinearLayout that has the padding round the button.
  2. Add the same onclick to the LinearLayout as the Button.
  3. In the Button set the duplicateParentState to true which make the button highlight when you click outside the button but inside the LinearLayout.

<LinearLayout
    android:layout_height="fill_parent"
    android:onClick="searchButtonClicked" 
    android:layout_centerVertical="true" 
    android:orientation="horizontal" 
    android:layout_width="wrap_content" 
    android:paddingRight="10dp" 
    android:paddingLeft="30dp">
    <Button 
        android:id="@+id/search_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/toggle_button_selector"
        android:textColor="#fff"
        android:text="Search"
        android:focusable="true"
        android:textStyle="bold"
        android:onClick="searchButtonClicked" 
        android:layout_gravity="center_vertical" 
        android:duplicateParentState="true"/>
</LinearLayout>

这篇关于我可以增加一个按钮的onclick面积编程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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