在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):afollestad/drag-select-recyclerview开源软件地址(OpenSource Url):https://github.com/afollestad/drag-select-recyclerview开源编程语言(OpenSource Language):Kotlin 100.0%开源软件介绍(OpenSource Introduction):Drag Select Recycler ViewThis library allows you to implement Google Photos style multi-selection in your apps! You start by long pressing an item in your list, then you drag your finger without letting go to select more. SampleYou can download a sample APK. Gradle DependencyThe Gradle dependency is available via jCenter. jCenter is the default Maven repository used by Android Studio. DependencyAdd the following to your module's dependencies {
implementation 'com.afollestad:drag-select-recyclerview:2.4.0'
} Introduction
This library will handle drag interception and auto scroll logic - if you drag to the top of the RecyclerView, the list will scroll up, and vice versa. DragSelectTouchListenerBasics
val receiver: DragSelectReceiver = // ...
val touchListener = DragSelectTouchListener.create(context, receiver) ConfigurationThere are a few things that you can configure, mainly around auto scroll. DragSelectTouchListener.create(context, adapter) {
// Configure the auto-scroll hotspot
hotspotHeight = resources.getDimensionPixelSize(R.dimen.default_56dp)
hotspotOffsetTop = 0 // default
hotspotOffsetBottom = 0 // default
// Listen for auto scroll start/end
autoScrollListener = { isScrolling -> }
// Or instead of the above...
disableAutoScroll()
// The drag selection mode, RANGE is the default
mode = RANGE
} The auto-scroll hotspot is a invisible section at the top and bottom of your RecyclerView, when your finger is in one of those sections, auto scroll is triggered and the list will move up or down until you lift your finger. If you use Compare it to the GIF at the top. InteractionA receiver looks like this: class MyReceiver : DragSelectReceiver {
override fun setSelected(index: Int, selected: Boolean) {
// do something to mark this index as selected/unselected
if(selected && !selectedIndices.contains(index)) {
selectedIndices.add(index)
} else if(!selected) {
selectedIndices.remove(index)
}
}
override fun isSelected(index: Int): Boolean {
// return true if this index is currently selected
return selectedItems.contains(index)
}
override fun isIndexSelectable(index: Int): Boolean {
// if you return false, this index can't be used with setIsActive()
return true
}
override fun getItemCount(): Int {
// return size of your data set
return 0
}
} In the sample project, our adapter is also our receiver. To start drag selection, you use val recyclerView: RecyclerView = // ...
val receiver: DragSelectReceiver = // ...
val touchListener = DragSelectTouchListener.create(context, receiver)
recyclerView.addOnItemTouchListener(touchListener) // important!!
// true for active = true, 0 is the initial selected index
touchListener.setIsActive(true, 0) |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论