ListView中的Item點擊和Button點擊焦點衝突

當ListView的Item中有Button的時候,會出現Button可以點擊,但是Item不可以點擊的問題。


解決辦法如下:

在ListView的每一個Item佈局文件的最外層佈局加上如下代碼: 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:descendantFocusability= "blocksDescendants"
          android:orientation="horizontal">

 

其次就是讓Item佈局中按鈕獲取不到焦點,但是要保證它可以響應點擊事件,在按鈕的佈局代碼中加上如下代碼:

<Button
        android:id="@+id/bt_receive_file"
        android:layout_width="60dip"
        android:layout_height="40dip"
        android:layout_marginLeft="5dip"
        android:textSize="17sp"
        android:focusable = "false"
        android:text="接收"/>

發佈了41 篇原創文章 · 獲贊 0 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章