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

Android中ListView的item點擊沒有反應的解決方法

 更新時間:2017年10月31日 09:20:37   作者:笑對空  
這篇文章主要介紹了Android中ListView的item點擊沒有反應的相關資料,需要的朋友可以參考下

如果stu_item.xml里面包括button或者checkbox等控件,默認情況下list的item會失去焦點,導致無法響應item的事件,最常用的解決辦法是在stu_item.xml的布局文件中設置descendantFocusability屬性。

該屬性是當一個為view獲取焦點時,定義viewGroup和其子控件兩者之間的關系。

屬性的值有三種:

 beforeDescendants:viewgroup會優(yōu)先其子類控件而獲取到焦點
 afterDescendants:viewgroup只有當其子類控件不需要獲取焦點時才獲取焦點
 blocksDescendants:viewgroup會覆蓋子類控件而直接獲得焦點
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="50dp"
 android:orientation="horizontal"
 android:descendantFocusability="blocksDescendants"><!--添加這個屬性--> 
 <ImageView
  android:id="@+id/img_head"
  android:layout_width="50dp"
  android:layout_height="50dp"
  android:src="@drawable/dog2"
  android:scaleType="centerCrop"
  android:layout_marginRight="5dp"/>
 <TextView
  android:layout_width="0dp"
  android:layout_weight="1"
  android:layout_height="wrap_content"
  android:layout_gravity="center_vertical"
  android:id="@+id/tv_name"/>
 <TextView
  android:layout_width="0dp"
  android:layout_weight="1"
  android:layout_height="wrap_content"
  android:layout_gravity="center_vertical"
  android:id="@+id/tv_age"/>
 <Button
  android:id="@+id/btn_delete"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_gravity="right"
  android:text="刪除"
  android:textColor="#ffffff"
  android:background="#ff0000"
  />
</LinearLayout>

效果圖:

這里寫圖片描述

總結

以上所述是小編給大家介紹的Android中ListView的item點擊沒有反應,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關文章

最新評論