作者jimbo05 (布丁恩)
看板AndroidDev
標題[問題]此layout會導致button無法觸發onClick嗎?
時間Thu Jul 18 01:55:21 2013
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
1F:推 Ansaga:一項都不能觸發嗎? 07/18 18:13
2F:→ issuemylove:button 加上 android:duplicateParentState="true"試 07/18 18:25
3F:→ jimbo05:後來發現layout加focusable那兩項會造成子button監聽屏蔽 07/18 21:47
4F:→ jimbo05:所以後來我改在背景放一大張imageView實現點擊的效果 07/18 21:48
5F:→ jimbo05:我會試試看二樓大大的方法 實在很感恩^^ 07/18 21:48