setRotationY(180) on recyclerview or viewpager creating scroll issue in Android 9(API 28)

我是研究僧i 提交于 2019-12-04 05:18:18

问题


I am managing RTL contents by implementing setRotationY for recyclerview and viewpagers but it seems that it is creating scroll/swipe issues in only devices with API 28 otherwise it is working perfectly fine. It is working perfectly fine if I remove setRotationY. Has anyone faced this issue? If so, how to solve it?

P.S. : Rotating 360f is not affecting the scroll but rotation 180f does.


回答1:


You can also use the layoutDirection in your recyclerview or viewpager like:

 <android.support.v4.view.ViewPager
        android:id="@+id/view_pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layoutDirection="locale"/>

Or the inflated View. So it will work perfectly.




回答2:


Check for the current version of SDK :

  if(Build.VERSION.SDK_INT >= 28) {
        // Call some material design APIs here

        recyclerView.setLayoutDirection(View.LAYOUT_DIRECTION_LOCALE);

    } else {
        // Implement this feature without material design
        recyclerView.setRotationY(180);


    }



回答3:


Issue was with this sliding tab strip library I was using. It would work perfectly as per other answers, we just have to add layoutDirection attribute to viewpager.




回答4:


I had this issue with ViewPager on API 28 because of ViewPager.setRotatingY(180) so that i can support RTL, I've tried replacing rotation with layoutDirection="locale", but it didn't work. I found a library for supporting RTL ViewPager here's a link https://github.com/duolingo/rtl-viewpager.

Add it to dependencies and just make sure you add layoutDirection="locale" to the 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"
     />

Update

ViewPager2 is locale friendly so it's automatically will change swipe direction according to the current device locale.

Some helpful links on the implementation of ViewPager2:

Android docs

Sample



来源:https://stackoverflow.com/questions/54129324/setrotationy180-on-recyclerview-or-viewpager-creating-scroll-issue-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!