欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android編程出現(xiàn)Button點(diǎn)擊事件無效的解決方法示例

 更新時(shí)間:2018年02月05日 12:15:43   作者:清澈@Cherry  
這篇文章主要介紹了Android編程出現(xiàn)Button點(diǎn)擊事件無效的解決方法,結(jié)合實(shí)例形式分析了Android編程中出現(xiàn)Button點(diǎn)擊事件無效的原因及相關(guā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ì)有所幫助。

相關(guān)文章

最新評(píng)論