Android Listview 子控件搶佔焦點

Listview通用問題,包括竄選啊、搶佔焦點,搶佔焦點的解決方案如下:
方案一:
給搶佔焦點的控件設置屬性

android:focusable="false"

方案二:
給Listview的item的根容器設置如下屬性:

android:descendantFocusability="blocksDescendants"

example

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:descendantFocusability="blocksDescendants"
    android:orientation="horizontal">

    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <Button
        android:id="@+id/ok"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:layout_marginRight="10dp"
        android:focusable="false"
        android:text="確定" />

</LinearLayout>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章