国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

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

2019-12-12 01:46:35
字體:
來源:轉載
供稿:網友

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

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

屬性的值有三種:

 beforeDescendants:viewgroup會優先其子類控件而獲取到焦點 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點擊沒有反應,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對武林網網站的支持!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 新余市| 东方市| 扶风县| 杂多县| 滕州市| 通州区| 谷城县| 仁寿县| 建平县| 洛浦县| 淄博市| 阿瓦提县| 大石桥市| 广宗县| 中牟县| 海伦市| 武安市| 乾安县| 陈巴尔虎旗| 武穴市| 靖西县| 上高县| 澜沧| 云南省| 独山县| 大邑县| 石城县| 商水县| 阿克苏市| 长丰县| 景东| 威海市| 莒南县| 高淳县| 武陟县| 黄骅市| 道孚县| 桦南县| 滨海县| 佛教| 昌吉市|