我正在尝试使用NonScrollingGridLayoutManager在recyclerview中实现网格,并且为了进行回调,我正在使用ItemTouchHelperCallback,以便可以在网格内的任何位置拖放项目。它可以正常工作,但随后变得迟钝并导致UI卡住。任何线索都会有很大帮助!
val recyclerView: RecyclerView = findViewById(R.id.revWords)
recyclerView.setHasFixedSize(true)
val layoutManager = NonScrollingGridLayoutManager(this)
layoutManager.flexDirection = FlexDirection.ROW
layoutManager.justifyContent = JustifyContent.CENTER
recyclerView.layoutManager = layoutManager
screenAdapter = ScreenAdapter(array) {
touchHelper.startDrag(it)
}
val callback = ItemTouchHelperCallback(adapter)
recyclerView.adapter = screenAdapter
touchHelper = ItemTouchHelper(callback)
touchHelper.attachToRecyclerView(recyclerView)