Android編程出現(xiàn)Button點(diǎn)擊事件無效的解決方法示例
本文實(shí)例講述了Android編程出現(xiàn)Button點(diǎn)擊事件無效的解決方法。分享給大家供大家參考,具體如下:
遇到這樣一個(gè)問題,給一個(gè)界面上方的按鈕添加了點(diǎn)擊事件,但死活沒反應(yīng),而放在界面下方的3個(gè)按鈕,都有相應(yīng)點(diǎn)擊事件,百度了一下無非有兩種可能:
1.button沒有初始化或者button初始化多次,導(dǎo)致混亂。
2.button點(diǎn)擊事件寫錯(cuò),無法監(jiān)聽。
但我確定的是這些都是沒有錯(cuò)的,后來找到的原因是下方的scroll布局覆蓋了上方的button的布局,使用了fill_parent,所以獲取不到點(diǎn)擊事件,如下出錯(cuò)代碼:
<?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" >
后來將上方的按鈕設(shè)置成高度40dp之后,將下方的scroll離上方有一段距離,就可以監(jiān)聽按鈕了。
更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android開發(fā)入門與進(jìn)階教程》、《Android調(diào)試技巧與常見問題解決方法匯總》、《Android編程之a(chǎn)ctivity操作技巧總結(jié)》、《Android操作json格式數(shù)據(jù)技巧總結(jié)》、《Android數(shù)據(jù)庫(kù)操作技巧總結(jié)》、《Android文件操作技巧匯總》、《Android資源操作技巧匯總》及《Android控件用法總結(jié)》
希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。
- Android實(shí)現(xiàn)輸入法彈出時(shí)把布局頂上去和登錄按鈕頂上去的解決方法
- android虛擬鍵盤彈出遮擋登陸按鈕問題的解決方法
- Android防止按鈕過快點(diǎn)擊造成多次事件的解決方法
- Android Button 自帶陰影效果另一種解決辦法
- Android setButtonDrawable()的兼容問題解決辦法
- Android中EditText+Button組合導(dǎo)致輸入板無法收起的原因分析及解決辦法
- 實(shí)例詳解Android解決按鈕重復(fù)點(diǎn)擊問題
- Android開發(fā)軟鍵盤遮擋登陸按鈕的完美解決方案
- Android優(yōu)雅的方式解決軟鍵盤遮擋按鈕問題
相關(guān)文章
Android實(shí)現(xiàn)淘寶倒計(jì)時(shí)功能
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)淘寶倒計(jì)時(shí),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-02-02Android基礎(chǔ)教程數(shù)據(jù)存儲(chǔ)之文件存儲(chǔ)
這篇文章主要介紹了Android基礎(chǔ)教程數(shù)據(jù)存儲(chǔ)之文件存儲(chǔ)的相關(guān)資料,數(shù)據(jù)存儲(chǔ)是Android開發(fā)的重要的知識(shí),這里提供了實(shí)例,需要的朋友可以參考下2017-07-07Android通過手機(jī)拍照或從本地相冊(cè)選取圖片設(shè)置頭像
微信、QQ、微博等社交類APP如何更換自己的頭像,這篇文章主要介紹了Android通過手機(jī)拍照或從本地相冊(cè)選取圖片設(shè)置頭像,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-07-07詳解Android 7.0 Settings 加載選項(xiàng)
本篇文章主要介紹了Android 7.0 Settings 加載選項(xiàng),Android 7.0 Settings頂部多了一個(gè)建議選項(xiàng),多了個(gè)側(cè)邊欄,操作更加便捷了,有興趣的可以了解一下。2017-02-02Android開發(fā)中的幾種網(wǎng)絡(luò)請(qǐng)求方式詳解
本篇文章主要包括Android中的幾種網(wǎng)絡(luò)請(qǐng)求方式詳解,具有一定的參考價(jià)值,有需要的可以了解一下。2016-11-11Android自定義ViewGroup打造各種風(fēng)格的SlidingMenu
這篇文章主要介紹了Android自定義ViewGroup打造各種風(fēng)格的SlidingMenu的相關(guān)資料,需要的朋友可以參考下2016-02-02