Android 具有GridLayoutManager的RecyclerView set PagerSnapHelper的spanCount超过2

Android 具有GridLayoutManager的RecyclerView set PagerSnapHelper的spanCount超过2,android,android-recyclerview,Android,Android Recyclerview,当设置GridLayoutManager的span计数为1时,PagerSnapHelper工作得最好。 但是,当set spanCount为3时,PagerSnapHelper必须非常用力地滚动。 使用span计数设置SnapHelper水平滚动GridLayoutManager的方式为3 PagerSnapHelper snapHelper = new PagerSnapHelper(); snapHelper.attachToRecyclerView(rvItemOriginalCon

当设置
GridLayoutManager
的span计数为1时,
PagerSnapHelper
工作得最好。 但是,当set spanCount为3时,
PagerSnapHelper
必须非常用力地滚动。 使用span计数设置
SnapHelper
水平滚动
GridLayoutManager
的方式为3

 PagerSnapHelper snapHelper = new PagerSnapHelper();
 snapHelper.attachToRecyclerView(rvItemOriginalContent);
 rvItemOriginalContent.setLayoutManager(new GridLayoutManager(context,
                                                                     3,
                                                                     GridLayoutManager.HORIZONTAL,
                                                                     false));

你能帮我吗,谢谢。

我已经解决了。当spanCount>1时,设置位置中心-spanCount

代码:

导入android.graphics.PointF;
导入android.support.annotation.NonNull;
导入android.support.annotation.Nullable;
导入android.support.v7.widget.LinearLayoutManager;
导入android.support.v7.widget.OrientationHelper;
导入android.support.v7.widget.RecyclerView;
导入android.support.v7.widget.SnapHelper;
导入android.view.view;
/**
*----VO NAD描述------
*/
公共类PagerSnapWithPanCountHelper
扩展SnapHelper{
私人国际货币基金组织;
私有布尔型mIsEnableCenter;
公共页NapWithPanCountHelper(int-mSpanCount,
布尔值(可访问中心){
//spanCount始终>=1
this.mSpanCount=mSpanCount;
this.mIsEnableCenter=mIsEnableCenter;
}
公共页NapWithPanCountHelper(int-mSpanCount){
//spanCount始终>=1
this.mSpanCount=mSpanCount;
}
//每个LayoutManager都会延迟创建方向帮助器。
@可空
私人定向助手mVerticalHelper;
@可空
私人定向助手mHorizontalHelper;
@可空
@凌驾
公共int[]CalculateInstanceOfInnalSnap(
@非Null final RecyclerView.LayoutManager LayoutManager,
@非空最终视图(目标视图){
int[]out=新的int[2];
if(layoutManager.canscroll()){
out[0]=是否可以输入错误?
距离中心(布局管理器,
targetView,
getHorizontalHelper(布局管理器)):
距离开始(targetView,
getHorizontalHelper(布局管理器));
}否则{
out[0]=0;
}
if(layoutManager.canScrollVertical()){
out[1]=错误的可访问性中心?
距离中心(布局管理器,
targetView,
getVerticalHelper(布局管理器)):
距离开始(targetView,
getVerticalHelper(布局管理器));
}否则{
out[1]=0;
}
返回;
}
私有视图findStartView(RecyclerView.LayoutManager LayoutManager,
方向辅助对象(辅助对象){
if(LinearLayoutManager的layoutManager实例){
int firstChild=((LinearLayoutManager)layoutManager).findFirstVisibleItemPosition();
布尔isLastItem=((LinearLayoutManager)layoutManager)
.findLastCompletelyVisibleItemPosition()
==layoutManager.getItemCount()-1;
if(firstChild==RecyclerView.NO_位置| | isLastItem){
返回null;
}
查看子项=layoutManager.findViewByPosition(第一个子项);
if(helper.getdecoratedD(子项)>=helper.getDecoratedMeasurement(子项)/2
&&helper.getDecoratedId(子项)>0){
返回儿童;
}否则{
if(((LinearLayoutManager)layoutManager).FindLastCompleteyVisibleItemPosition()
==layoutManager.getItemCount()-1){
返回null;
}否则{
返回layoutManager.findViewByPosition(firstChild+1);
}
}
}
返回findSnapView(布局管理器);
}
/*
中心项目。
* */
@可空
私有视图FindCenter视图(RecyclerView.LayoutManager LayoutManager,
方向辅助对象(辅助对象){
int childCount=layoutManager.getChildCount();
if(childCount==0){
返回null;
}
View closestChild=null;
最终国际中心;
if(layoutManager.getcliptoppadding()){
中心=helper.getStartAfterPadding()+helper.getTotalSpace()/2;
}否则{
center=helper.getEnd()/2;
}
int=Integer.MAX\u值;
for(int i=0;i