android实现实现RecyclerView列表单选功能列表单选功能
主要为大家详细介绍了android实现RecyclerView列表单选功能,具有一定的参考价值,感兴趣的小伙伴们可以
参考一下
本文实例为大家分享了android实现RecyclerView列表单选功能的具体代码,供大家参考,具体内容如下
实现思维实现思维
1.首先在一行的xml布局中添加一个选中效果的icon图片,未选中的情况下INVISIBLE或者GONE 都可以,推荐使用INVISIBLE
它会占用布局位置但是不显示,这样可以避免布局中其他控件因为勾选布局的消失而轻微变动位置
2.将适配器类中的onCreateViewHolder方法重写添加按键监听,onBindViewHolder方法中重写添加判断点击的位置(具体原
理请查看下面贴的代码)
PS:
RecyclerView的实现全部方法就不贴出来了,本人的博客中有RecyclerView各种实现效果文章
1.首先在一行的xml布局中添加一个选中效果的icon图片,未选中的情况下INVISIBLE或者GONE 都可以,推荐使用INVISIBLE
它会占用布局位置但是不显示,这样可以避免布局中其他控件因为勾选布局的消失而轻微变动位置
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/DeviceList_Layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp">
<ImageView
android:id="@+id/DeviceList_ImageView"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:src="@mipmap/preview_image_boy"
android:layout_gravity="center"/>
<TextView
android:id="@+id/DeviceList_NameText"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="名称"
android:textSize="@dimen/BigTextSize"
android:textColor="@color/colorBlue"
android:layout_gravity="center"
android:layout_marginLeft="20dp"
android:maxLines="1"/>
<ImageView
android:id="@+id/DeviceList_Select"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:src="@mipmap/ic_select"
android:visibility="invisible"
android:layout_marginLeft="10dp"
android:layout_gravity="center"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="1px"
android:background="@color/colorBlue"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp">
</LinearLayout>
</LinearLayout>
效果图:
评论0