item嵌套button使listview onitemClick事件不响应
16lz
2021-12-04
解决方法:让button失去焦点,设置android:focusable="false",在item xml文件的根布局设置android:descendantFocusability="blocksDescendants"
代码:listview.xml
item.xml布局文件:
代码:listview.xml
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent" android:layout_height="fill_parent"android:background="@color/white"><include layout="@layout/main_title" android:id="@+id/main_title_id" /><ListView android:layout_width="fill_parent" android:layout_height="fill_parent"android:divider="@null" android:listSelector="@android:color/transparent"android:dividerHeight="10dip" android:layout_below="@id/main_title_id" android:id="@+id/ye_listview_id" /><include android:layout_centerHorizontal="true"android:layout_centerInParent="true" android:layout_width="wrap_content"android:visibility="gone" android:layout_height="90dip" layout="@layout/progressbar" /></RelativeLayout>
item.xml布局文件:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent" android:layout_height="wrap_content"android:orientation="horizontal" android:descendantFocusability="blocksDescendants" ><RelativeLayout android:layout_width="fill_parent"android:background="@drawable/ye_list_bg_selector"android:layout_height="wrap_content" android:gravity="center_vertical"><RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/relat_img_id"android:gravity="center_vertical"><ImageView android:id="@+id/ye_item_img"android:layout_height="60dip" android:layout_width="97dip"android:layout_marginLeft="10dip"/><Button android:id="@+id/list_price_id" android:layout_width="55.55dip"android:layout_height="16dip" android:background="@drawable/list_price_bg"android:layout_alignBottom="@id/ye_item_img" android:textSize="13sp"android:textColor="@color/white" android:focusable="false"android:layout_alignRight="@id/ye_item_img" android:gravity="right|top" /></RelativeLayout><RelativeLayout android:layout_width="wrap_content"android:layout_height="wrap_content" android:layout_marginLeft="10dip"android:layout_toRightOf="@id/relat_img_id"><TextView android:id="@+id/ye_item_text1_id"android:layout_gravity="center_vertical" android:singleLine="true"android:layout_width="wrap_content" android:layout_height="wrap_content"android:text="XXXXX" android:textColor="@color/black"android:textSize="16sp" /><TextView android:id="@+id/ye_item_text2_id"android:layout_width="wrap_content" android:layout_height="wrap_content"android:ellipsize="end" android:maxLines="2" android:textColor="@color/gray"android:textSize="13sp" android:text="XXXXX" android:layout_below="@id/ye_item_text1_id" /><TextView android:id="@+id/ye_item_text3_id" android:textSize="13sp"android:layout_width="wrap_content" android:layout_height="wrap_content"android:text="XXXXX" android:layout_below="@id/ye_item_text2_id" /></RelativeLayout></RelativeLayout></LinearLayout>
更多相关文章
- NPM 和webpack 的基础使用
- 【阿里云镜像】使用阿里巴巴DNS镜像源——DNS配置教程
- Android(安卓)TextView 组件
- Android(安卓)layout xml总结
- android 随手记之文件+参数上传请求
- 关于android原生Webview的一些属性整理(持续补充~)
- Linux/Ubuntu下android设备添加adb驱动
- android APK签名过程之CERT.SF分析
- 恢复工厂设置流程