Skip to content

Commit 1707b02

Browse files
author
李泽鹏
committed
添加wraplinearlayout
1 parent f424673 commit 1707b02

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.gxyj.base.widget
2+
3+
import android.content.Context
4+
import android.support.v7.widget.LinearLayoutManager
5+
import android.support.v7.widget.RecyclerView
6+
import android.util.AttributeSet
7+
8+
/**
9+
* 解决rv 内外数据不一致造成的IndexOutOfBoundsException
10+
* https://www.jianshu.com/p/2eca433869e9
11+
* https://www.jianshu.com/p/840feaafc768
12+
* https://www.jianshu.com/p/654dac931667
13+
* 这里主要是配合notifyItemRangeChanged使用,这个虽然可以确保刷新不闪烁,但是会导致数据不一致
14+
*/
15+
class WrapContentLinearLayoutManager : LinearLayoutManager {
16+
17+
constructor(context: Context) : super(context)
18+
constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes)
19+
constructor(context: Context?, orientation: Int, reverseLayout: Boolean) : super(context, orientation, reverseLayout)
20+
21+
override fun onLayoutChildren(recycler: RecyclerView.Recycler?, state: RecyclerView.State?) {
22+
try {
23+
super.onLayoutChildren(recycler, state)
24+
} catch (e: IndexOutOfBoundsException) {
25+
e.printStackTrace()
26+
}
27+
}
28+
}

0 commit comments

Comments
 (0)