我想实现图片上的效果并且无限滑动
// mLayoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false);
CustomLayoutManager man = new CustomLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false);
LinearSnapHelper mLinearSnapHelper = new LinearSnapHelper();
appRecyclerView.setLayoutManager(man);
appBannerAdapter = new AppBannerAdapter(getActivity(), appBannerList);
appRecyclerView.setAdapter(appBannerAdapter);
mLinearSnapHelper.attachToRecyclerView(appRecyclerView);
// RecyclerView.LayoutManager manager = appRecyclerView.getLayoutManager();
// manager.scrollToPosition(0);
// manager.scrollToPosition(Integer.MAX_VALUE/2);
// manager.smoothScrollToPosition(appRecyclerView,null,Integer.MAX_VALUE/2+2);
appRecyclerView.scrollToPosition(0);
appRecyclerView.scrollToPosition(Integer.MAX_VALUE/2);
appRecyclerView.smoothScrollToPosition(Integer.MAX_VALUE/2+2);//快速移动到
// manager.scrollToPosition(Integer.MAX_VALUE/2);
代码是上面这样写的,两个滑动方法在中兴手机和魅族手机上都会失效,在我的华为手机上显示正常,求解决办法
更新 我昨天用了其他方法还是不行 下面贴上代码
// RecyclerView.LayoutManager manager = appRecyclerView.getLayoutManager();
// manager.scrollToPosition(0);
// manager.scrollToPosition(Integer.MAX_VALUE/2);
// manager.smoothScrollToPosition(appRecyclerView,null,Integer.MAX_VALUE/2+2);
// appRecyclerView.scrollToPosition(Integer.MAX_VALUE/2);
moveToPosition(Integer.MAX_VALUE/2);
appRecyclerView.stopScroll();
// appRecyclerView.scrollToPosition(Integer.MAX_VALUE/2);
// appRecyclerView.smoothScrollToPosition(Integer.MAX_VALUE/2+2);//快速移动到
}
private void moveToPosition(int n) {
int firstItem = mLayoutManager.findFirstVisibleItemPosition();
int lastItem = mLayoutManager.findLastVisibleItemPosition();
if (n <= firstItem ){
appRecyclerView.scrollToPosition(n);
}else if ( n <= lastItem ){
int top = appRecyclerView.getChildAt(n - firstItem).getRight();
appRecyclerView.scrollBy(0, top);
}else{
appRecyclerView.scrollToPosition(n);
}
}
private void smoothMoveToPosition(int n) {
int firstItem = mLayoutManager.findFirstVisibleItemPosition();
int lastItem = mLayoutManager.findLastVisibleItemPosition();
if (n <= firstItem ){
appRecyclerView.smoothScrollToPosition(n);
}else if ( n <= lastItem ){
int top = appRecyclerView.getChildAt(n - firstItem).getLeft();
appRecyclerView.smoothScrollBy(0, top);
}else{
appRecyclerView.smoothScrollToPosition(n);
}
}