我正在使用此功能滚动到水平回收站视图中的选定位置。问题是,如果我滚动回收器,然后单击某个项目,则它不会到达视图的中心。相反,如果我不滚动回收站,它将起作用。 当我单击一个项目时,我正在使用此方法。该位置是adapterPosition。
override fun scrollToSelected(position: Int, isLeftScroll: Boolean) {
if(!isLeftScroll || position == 0) contactRV.layoutManager?.smoothScrollToPosition(contactRV, RecyclerView.State(), position +1)
else contactRV.layoutManager?.smoothScrollToPosition(contactRV, RecyclerView.State(), position-1)
我该怎么做才能解决此问题?
答案 0 :(得分:0)
您将实现[ERROR] : Script Error Couldn't find module:
/com.alcoapps.socialshare/com.alcoapps.socialshare for architecture: x86_64
的方法RecyclerView.SmoothScroller
。
onTargetFound(View, State, Action)
特别是在/**
* Called when the target position is laid out. This is the last callback SmoothScroller
* will receive and it should update the provided {@link Action} to define the scroll
* details towards the target view.
* @param targetView The view element which render the target position.
* @param state Transient state of RecyclerView
* @param action Action instance that you should update to define final scroll action
* towards the targetView
*/
abstract protected void onTargetFound(View targetView, State state, Action action);
和LinearLayoutManager
中:
LinearSmoothScroller