在使用LinelayoutManager.scrollToPositionWithOffset()方法时,如果第一次调用没有生效,可以尝试以下方法来让项目滚动到Recycleview顶部:
recyclerView.post(new Runnable() {
@Override
public void run() {
layoutManager.scrollToPositionWithOffset(position, offset);
}
});
layoutManager = new LinearLayoutManager(context);
recyclerView.setLayoutManager(layoutManager);
recyclerView.smoothScrollToPosition(position);
希望以上方法能够帮助您解决滚动到Recycleview顶部的问题。如果您需要更多关于RecyclerView的信息,可以参考腾讯云的相关产品文档:RecyclerView。
领取专属 10元无门槛券
手把手带您无忧上云