[問題]此layout會導致button無法觸發onClick嗎?

看板AndroidDev作者 (布丁恩)時間11年前 (2013/07/18 01:55), 編輯推噓1(104)
留言5則, 3人參與, 最新討論串1/1
layout的xml如下,裡面的button無論是 OnTouch、OnFocusChange、OnClick皆無法觸發.. 爬過一些文章說是OnTouch、OnClick同時存在時, OnTouch一定要return false這樣OnClick才能觸發, 我照做了也確保return false,但button還是無法觸發這三項...... 請問是因為我在RelativeLayout設定focusable、focusableInTouchMode的緣故嗎? 感謝各位高手協助! <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/test_layout" android:focusable="true" android:focusableInTouchMode="true"> <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:textSize="30dp" android:layout_marginTop="19dp" android:text="@string/num" /> <ListView android:id="@+id/listView1" android:layout_width="285dp" android:layout_height="200dp" android:layout_below="@+id/textView1" android:layout_centerHorizontal="true" android:layout_marginTop="15dp" > </ListView> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:layout_marginBottom="36dp" android:text="@string/ok" /> </RelativeLayout> -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.224.92.190

07/18 18:13, , 1F
一項都不能觸發嗎?
07/18 18:13, 1F

07/18 18:25, , 2F
button 加上 android:duplicateParentState="true"試
07/18 18:25, 2F

07/18 21:47, , 3F
後來發現layout加focusable那兩項會造成子button監聽屏蔽
07/18 21:47, 3F

07/18 21:48, , 4F
所以後來我改在背景放一大張imageView實現點擊的效果
07/18 21:48, 4F

07/18 21:48, , 5F
我會試試看二樓大大的方法 實在很感恩^^
07/18 21:48, 5F
文章代碼(AID): #1HvjgCUJ (AndroidDev)