Closed everyOneNo closed 10 months ago
有更好的方法的话可以告诉我
mBanner1.getViewPager2().addItemDecoration(new RecyclerView.ItemDecoration() { @Override public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) { super.getItemOffsets(outRect, view, parent, state); outRect.left = -100; outRect.right = -100; } }); try { Class<ViewPager2> viewPager2Class = ViewPager2.class; Field[] f = viewPager2Class.getDeclaredFields(); for (Field item : f) { if (item.getName().equals("mRecyclerView")) { item.setAccessible(true); RecyclerView recyclerView = (RecyclerView) item.get(mBanner1.getViewPager2()); if (recyclerView != null) { recyclerView.setChildDrawingOrderCallback(new RecyclerView.ChildDrawingOrderCallback() { @Override public int onGetChildDrawingOrder(int childCount, int i) { int r; if (1 == i) { r = 2; } else if (2 == i) { r = 1; } else { r = i; } if (r <= childCount - 1) { return r; } return i; } }); } } } } catch (Exception e) { e.printStackTrace(); }
有更好的方法的话可以告诉我