咳咳! 今天来搞一下子 RecyclerView+瀑布流+刷新+侧滑栏
今天用kotlin来搞的:
1、线性列表、网格列表、瀑布流
2、(线性列表、网格列表、瀑布流) 刷新、加载
3、(线性列表、网格列表、瀑布流) 刷新、加载、侧滑栏(滑动列表关闭所有侧滑栏、保留所有侧滑栏、保证只存在一个侧滑栏)
刷新加载的功能实现:在v7 recycleListView 基础上使用 SpringView 库来扩展 ( https://github.com/liaoinstan/SpringView 提供了多种刷新样式可选择)
<com.liaoinstan.springview.widget.SpringView
android:id="@+id/springView"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycleListView"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v7.widget.RecyclerView>
</com.liaoinstan.springview.widget.SpringView>
实现局部刷新: ( https://www.jianshu.com/p/de8601f357a9 )
override fun onBindViewHolder(holder: ViewHolder, position: Int, payloads:
MutableList<Any>) {
super.onBindViewHolder(holder, position, payloads)
//局部刷新处理
if(payloads.isEmpty()){
onBindViewHolder(holder,position)
}else{
val name = (payloads[0] as RecycleDataBean).name
val image = (payloads[0] as RecycleDataBean).image
(holder as DemoViewHolder).mText!!.text = name
Glide.with(mContext).load(image!!).apply(mOptions).into(holder.mImage!!)
}
}
实现侧滑:( https://github.com/Dsiner/SlideLayout ) 处理列表滑动是否关闭已经展开的侧滑栏
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="wrap_content">
<com.d.lib.slidelayout.SlideLayout
android:id="@+id/slideLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- 内容view展示 -->
<RelativeLayout
android:layout_width="match_parent"
android:background="@color/colorPrimaryDark"
android:gravity="center"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/videoImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"/>
<TextView
android:id="@+id/nameTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="30dp"
android:ellipsize="end"
android:textColor="#eee"
android:text=""/>
</RelativeLayout>
<!-- Slide view -->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_stick"
android:layout_width="80dp"
android:layout_height="match_parent"
android:background="@color/colorYellow"
android:gravity="center"
android:text="STICK"
android:textColor="@color/colorBlack"
android:textSize="14dp" />
<TextView
android:id="@+id/tv_delete"
android:layout_width="80dp"
android:layout_height="match_parent"
android:background="@color/colorBlue"
android:gravity="center"
android:text="DELETE"
android:textColor="@color/colorBlack"
android:textSize="14dp" />
</LinearLayout>
</com.d.lib.slidelayout.SlideLayout>
</RelativeLayout>
RecycleListAdapter{
................
private var nowSelectPosition:Int = 0 //记录当前选择的侧滑栏一条,定位处理滑动而不关闭侧滑
private var mSlideManager:SlideManager?=null
init {
mSlideManager = SlideManager()
}
//侧滑栏的实现
holder.mSlideLayout!!.setOpen(mEntityList!![position].isOpen!!,false)
holder.mSlideLayout!!.setOnStateChangeListener(object :SlideLayout.OnStateChangeListener{
override fun closeAll(layout: SlideLayout?): Boolean {
//return mSlideManager!!.closeAll(layout) //关闭所有已经展开的侧滑栏
return false //返回false 不关闭展开的侧滑栏
}
override fun onChange(layout: SlideLayout?, isOpen: Boolean) {
//根据记录侧滑的当前position来处理,只有一条侧滑展开
if(nowSelectPosition==0){
nowSelectPosition = position
mEntityList!![position].isOpen = true
mSlideManager!!.onChange(layout, isOpen)
}else{
nowSelectPosition = 0
mEntityList!![position].isOpen = false
mSlideManager!!.onChange(layout, isOpen)
mSlideManager!!.closeAll(layout)
}
//处理成,多条侧滑展开的效果
//mEntityList!![position].isOpen = true
//mSlideManager!!.onChange(layout, isOpen)
}
})
................
}
demo源码:https://download.csdn.net/download/u010326875/11377210