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
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程