日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

RecycleView弹性滑动

發布時間:2023/12/9 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 RecycleView弹性滑动 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

還有點bug,建議使用?LinearSnapHelper

rvPilotList.addOnScrollListener(new RecyclerView.OnScrollListener() {@Overridepublic void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {super.onScrolled(recyclerView, dx, dy);// offsetY += dy; // // int first = linearLayoutManager.findFirstCompletelyVisibleItemPosition(); // int last = linearLayoutManager.findLastCompletelyVisibleItemPosition(); // View firstview = linearLayoutManager.findViewByPosition(first); // if (viewWidth == 0) { // viewWidth = firstview.getHeight(); // } // int offseta = firstview.getTop(); // float sx = 1f + (float) offseta / viewWidth; // if (offsetY == 0) { // View view = linearLayoutManager.findViewByPosition(first + 1); // scaleUp(view); // } // // firstview.setScaleX(sx); // View lastview = linearLayoutManager.findViewByPosition(last); // offseta = recyclerView.getHeight() - lastview.getBottom(); // sx = 1f + (float) offseta / viewWidth; // lastview.setScaleX(sx);}@Overridepublic void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {super.onScrollStateChanged(recyclerView, newState);if (newState == 0) {int visibleItem = linearLayoutManager.getChildCount();int coun = 0;if (visibleItem % 2 == 1) {coun = (visibleItem - 1) / 2;} else {coun = visibleItem / 2;}Log.i(TAG, "onScrollStateChanged: " + visibleItem);Log.i(TAG, "onScrollStateChanged: coun" + coun);int postion = linearLayoutManager.findFirstVisibleItemPosition();Log.i(TAG, "onScrollStateChanged: postion" + postion);View view;Log.i(TAG, "findFirstCompletelyVisibleItemPosition: " + linearLayoutManager.findFirstCompletelyVisibleItemPosition());if (postion == 0 && linearLayoutManager.findFirstCompletelyVisibleItemPosition() != 0) {view = linearLayoutManager.findViewByPosition(0);} else {view = linearLayoutManager.findViewByPosition(postion + coun);}int pm = ((ViewGroup) view.getParent()).getMeasuredWidth();int left = view.getLeft() + view.getWidth() / 2;int offset = 0;if (left == pm / 2) {return;}if (left < pm / 2) {offset = -(pm / 2 - left);} else {offset = left - pm / 2;}rvPilotList.smoothScrollBy(offset, 0);}}});

  

轉載于:https://www.cnblogs.com/6324/p/10733971.html

總結

以上是生活随笔為你收集整理的RecycleView弹性滑动的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。