我正在研究只运行在一个devicerunning KitKat上的Android应用程序。平滑滚动不适用于Android的初始滚动RecyclerView
RecylerView的平滑滚动功能我用于其他物理平板电脑和genymotion不幸停止工作在一个设备上它需要处理。
而不是滚动到某个位置,它会通过目标位置并一直滚动到底部,看起来非常糟糕。
我能够追溯到RecyclerView类中的抽象SmoothScroller的错误。
if (getChildPosition(mTargetView) == mTargetPosition) {
onTargetFound(mTargetView, recyclerView.mState, mRecyclingAction);
mRecyclingAction.runIfNecessary(recyclerView);
stop();
} else {
Log.e(TAG, "Passed over target position while smooth scrolling.");
mTargetView = null;
}
我使用的是SnappingLinearLayoutManager,我在网上找到的,但与Android的正常LinearLayoutManager换出来,和我仍然有同样的问题。
该列表长7个项目(用户每次可以看到4个),并滚动到第5个项目(位置4)项目。
当我滚动到第3个时,我没有收到此错误。
此外,我上下滚动列表一次后,错误停止发生。
编辑: 我能够使用layoutManager.scrollToPositionWithOffset();但我试图用平滑滚动动画来做到这一点。
下面是一些我的代码和细节:
private void setupMainRecyclerViewWithAdapter() {
mainLayoutManager = new SnappingLinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
mainListRecyclerView.setLayoutManager(mainLayoutManager);
settingsMainListAdapter = new SettingsListAdapter(SettingsActivity.this,
settingsPresenter.getSettingsItems(),
settingsPresenter);
mainListRecyclerView.setAdapter(settingsMainListAdapter);
mainListRecyclerView.addItemDecoration(new BottomOffsetDecoration(EXTRA_VERTICAL_SCROLLING_SPACE));
}
@Override
public void scrollMainList(boolean listAtTop) {
if(listAtTop) {
mainListRecyclerView.smoothScrollToPosition(4);
moveMainMoreButtonAboveList();
} else {
mainListRecyclerView.smoothScrollToPosition(0);
moveMainMoreButtonBelowList();
}
}
尝试使用'layoutManager.scrollToPosition(指数);'而不是 – BNK
对不起,我应该说我能使用的layoutManager。 scrollToPositionWithOffset();但我试图用平滑滚动动画来做到这一点。 好抓住@BNK。我会将该编辑添加到我的问题中。 – SamIAmHarris
也许他们可以帮助https://mcochin.wordpress.com/2015/05/13/android-customizing-smoothscroller-for-the-recyclerview/和https://blog.stylingandroid.com/scrolling-recycler-view-第2部分/ – BNK