Good_Wen 2017-09-20 08:17 采纳率: 0%
浏览 6049
已结题

recyclerView本身的scrollToPosition方法失效

图片说明
我想实现图片上的效果并且无限滑动
// 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);
    }

}
  • 写回答

1条回答 默认 最新

  • Good_Wen 2017-09-21 02:03
    关注

    目前已经实现了效果了。但是在部分手机上是无效的,求路过的大神们帮忙下

    评论

报告相同问题?

悬赏问题

  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示