Android RecyclerView 滑动到指定item(position)并加动画 | 您所在的位置:网站首页 › 安卓滑动阻尼调整 › Android RecyclerView 滑动到指定item(position)并加动画 |
其实Android RecyclerView组件已经自带了移动方法: RecyclerView.scrollToPosition(position) //没有动画效果 但是这个方法没有动画效果,很生硬,直接就滑动过去了,下面来看一个有滑动动画效果的: val smoothScroller= object : androidx.recyclerview.widget.LinearSmoothScroller(this) {//this是Context override fun getVerticalSnapPreference(): Int { return SNAP_TO_START } } smoothScroller.targetPosition = position//position是item的位置 RecyclerView.layoutManager!!.startSmoothScroll(smoothScroller)//通过RecyclerView的layoutManager来实现移动动画效果以上就是Android RecyclerView移动到指定item的代码,我也是从其他地方找来的,但是找不到地址了,记录一下,方便以后使用。 |
CopyRight 2018-2019 实验室设备网 版权所有 |