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

Android中ListView的item點(diǎn)擊沒(méi)有反應(yīng)的解決方法

 更新時(shí)間:2017年10月31日 09:20:37   作者:笑對(duì)空  
這篇文章主要介紹了Android中ListView的item點(diǎn)擊沒(méi)有反應(yīng)的相關(guān)資料,需要的朋友可以參考下

如果stu_item.xml里面包括button或者checkbox等控件,默認(rèn)情況下list的item會(huì)失去焦點(diǎn),導(dǎo)致無(wú)法響應(yīng)item的事件,最常用的解決辦法是在stu_item.xml的布局文件中設(shè)置descendantFocusability屬性。

該屬性是當(dāng)一個(gè)為view獲取焦點(diǎn)時(shí),定義viewGroup和其子控件兩者之間的關(guān)系。

屬性的值有三種:

 beforeDescendants:viewgroup會(huì)優(yōu)先其子類(lèi)控件而獲取到焦點(diǎn)
 afterDescendants:viewgroup只有當(dāng)其子類(lèi)控件不需要獲取焦點(diǎn)時(shí)才獲取焦點(diǎn)
 blocksDescendants:viewgroup會(huì)覆蓋子類(lèi)控件而直接獲得焦點(diǎn)
<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"><!--添加這個(gè)屬性--> 
 <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>

效果圖:

這里寫(xiě)圖片描述

總結(jié)

以上所述是小編給大家介紹的Android中ListView的item點(diǎn)擊沒(méi)有反應(yīng),希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評(píng)論