首页 > 解决方案 > recyclerview 或 viewpager 上的 setRotationY(180) 在 Android 9(API 28)中创建滚动问题

问题描述

我通过为 recyclerview 和 viewpagers 实现 setRotationY 来管理 RTL 内容,但它似乎只在具有 API 28 的设备中创建滚动/滑动问题,否则它工作得很好。如果我删除 setRotationY,它工作得很好。有没有人遇到过这个问题?如果是这样,如何解决?

PS:旋转 360f 不会影响滚动,但旋转 180f 会。

标签: androidandroid-recyclerviewandroid-viewpagerandroid-9.0-pie

解决方案


由于 ViewPager.setRotatingY(180) 我在 API 28 上遇到了 ViewPager 的这个问题,所以我可以支持 RTL,我尝试用 layoutDirection="locale" 替换旋转,但它没有用。我找到了一个支持 RTL ViewPager 的库,这是一个链接https://github.com/duolingo/rtl-viewpager

将其添加到依赖项并确保将 layoutDirection="locale" 添加到 RtlViewPager

<com.duolingo.open.rtlviewpager.RtlViewPager
        android:layoutDirection="locale"
        android:keepScreenOn="true"
        android:id="@+id/quranViewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:animateLayoutChanges="true"
     />

更新

ViewPager2 对区域设置友好,因此它会根据当前设备区域设置自动更改滑动方向。

有关 ViewPager2 实现的一些有用链接:

安卓文档

样本


推荐阅读