Android Button 点击事件无效

       遇到这样一个问题,给一个界面上方的按钮添加了点击事件,但死活没反应,而放在界面下方的3个按钮,都有相应点击事件,百度了一下无非有两种可能:

       1.button没有初始化或者button初始化多次,导致混乱。

       2.button点击事件写错,无法监听。

       

         但我确定的是这些都是没有错的,后来找到的原因是下方的scroll布局覆盖了上方的button的布局,使用了fill_parent,所以获取不到点击事件,如下出错代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/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离上方有一段距离,就可以监听按钮了。

  • 4
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值