Android编程出现Button点击事件无效的解决方法示例
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Android编程出现Button点击事件⽆效的解决⽅法⽰例
本⽂实例讲述了Android编程出现Button点击事件⽆效的解决⽅法。
分享给⼤家供⼤家参考,具体如下:
遇到这样⼀个问题,给⼀个界⾯上⽅的按钮添加了点击事件,但死活没反应,⽽放在界⾯下⽅的3个按钮,都有相应点击事件,百度了⼀下⽆⾮有两种可能:
1.button没有初始化或者button初始化多次,导致混乱。
2.button点击事件写错,⽆法监听。
但我确定的是这些都是没有错的,后来找到的原因是下⽅的scroll布局覆盖了上⽅的button的布局,使⽤了fill_parent,所以获取不到点击事件,如下出错代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="<span style="font-family: Arial, Helvetica, sans-serif;">fill_parent</span><span style="font-family: Arial, Helvetica, sans-serif;">"</span> android:orientation="horizontal" >
<Button
android:id="@+id/canshusback"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:background="@drawable/last" />
</LinearLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:id="@+id/allti"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical" >
后来将上⽅的按钮设置成⾼度40dp之后,将下⽅的scroll离上⽅有⼀段距离,就可以监听按钮了。
更多关于Android相关内容感兴趣的读者可查看本站专题:《》、《》、《》、《》、《》、《》、《》及《》
希望本⽂所述对⼤家Android程序设计有所帮助。