解决RecyclerView使用smoothScrollToPosition方法时,item顶部显示不全的bug
TopLinearSmoothScroller topLinearSmoothScroller;
LinearLayoutManager mLinearLayoutManager = new LinearLayoutManager(context) {
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {
super.smoothScrollToPosition(recyclerView, state, position);
if (topLinearSmoothScroller == null)
topLinearSmoothScroller = new TopLinearSmoothScroller(recyclerView.getContext());
topLinearSmoothScroller.setTargetPosition(position);
startSmoothScroll(topLinearSmoothScroller);
}
};
mRecyclerView.setLayoutManager(mLinearLayoutManager);
public class TopLinearSmoothScroller extends LinearSmoothScroller {
public TopLinearSmoothScroller(Context context) {
super(context);
}
@Override
public int getVerticalSnapPreference() {
return SNAP_TO_START;
}
}
网友评论