Android編程出現(xiàn)Button點(diǎn)擊事件無效的解決方法示例
本文實(shí)例講述了Android編程出現(xiàn)Button點(diǎn)擊事件無效的解決方法。分享給大家供大家參考,具體如下:
遇到這樣一個問題,給一個界面上方的按鈕添加了點(diǎn)擊事件,但死活沒反應(yīng),而放在界面下方的3個按鈕,都有相應(yīng)點(diǎn)擊事件,百度了一下無非有兩種可能:
1.button沒有初始化或者button初始化多次,導(dǎo)致混亂。
2.button點(diǎn)擊事件寫錯,無法監(jiān)聽。
但我確定的是這些都是沒有錯的,后來找到的原因是下方的scroll布局覆蓋了上方的button的布局,使用了fill_parent,所以獲取不到點(diǎn)擊事件,如下出錯代碼:
<?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ù)庫操作技巧總結(jié)》、《Android文件操作技巧匯總》、《Android資源操作技巧匯總》及《Android控件用法總結(jié)》
希望本文所述對大家Android程序設(shè)計(jì)有所幫助。
- Android實(shí)現(xiàn)輸入法彈出時把布局頂上去和登錄按鈕頂上去的解決方法
- 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 Intent啟動別的應(yīng)用實(shí)現(xiàn)方法
我們知道Intent的應(yīng)用,可以啟動別一個Activity,那么是否可以啟動別外的一個應(yīng)用程序呢,答案是可以的2013-04-04
android內(nèi)存優(yōu)化之圖片優(yōu)化
對圖片本身進(jìn)行操作。盡量不要使用setImageBitmap、setImageResource、BitmapFactory.decodeResource來設(shè)置一張大圖,因?yàn)檫@些方法在完成decode后,最終都是通過java層的createBitmap來完成的,需要消耗更多內(nèi)存2012-12-12
Android實(shí)現(xiàn)面包屑功能的代碼(支持Fragment聯(lián)動)
這篇文章主要介紹了Android實(shí)現(xiàn)面包屑功能的代碼(支持Fragment聯(lián)動),本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-05-05
Android(2.2/2.3系統(tǒng))Gallery解決默認(rèn)和橫豎屏切換選中狀態(tài)問題
本文主要介紹Android Gallery,在Android開發(fā)過程中肯定會遇到版本不同,在開發(fā)過程中需要調(diào)整的,這里針對Android(2.2/2.3系統(tǒng)版本) Gallery解決默認(rèn)和橫豎屏切換選中狀態(tài)問題2016-07-07
Flutter 側(cè)滑欄及城市選擇UI的實(shí)現(xiàn)方法
這篇文章主要介紹了Flutter 側(cè)滑欄及城市選擇UI的實(shí)現(xiàn),本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下2019-07-07

