how to make my viewpager swipe from right to left

前端 未结 13 623
一整个雨季
一整个雨季 2020-12-05 14:42

I have a viewpager and it contains some information but it lets me swipe the pages from left to right how can I make it swipe from left to right which means change its direc

相关标签:
13条回答
  • 2020-12-05 15:03

    You can swipe in both directions already. By default it shows page zero, but you could change that:

    protected void onCreate(Bundle savedInstanceState) {
        // ...
        viewPager.setCurrentItem(myFragmentCount-1); 
        // ...
    
    0 讨论(0)
  • 2020-12-05 15:03

    First u need to implements OnPageChangeListener in your class and second set the listener to your viewpager like viewpager.setOnPageChangeListener(yourclass.this); Hope This will work.

    0 讨论(0)
  • 2020-12-05 15:05

    You don't any third party library. Android recently added new UI component called ViewPager2 which supports RTL View Pager.

    https://developer.android.com/jetpack/androidx/releases/viewpager2

    Please find below link to an answer. The answer talks about Migration guide and sample github app to support RTL view pager.

    https://stackoverflow.com/a/59558911/651377

    0 讨论(0)
  • 2020-12-05 15:06

    It is the very simple technique to change the swipe direction of the Viewpager.

    There are two simple step which has to follow you,

    1. Change the rotation of the View pager,

    viewpager.setRotationY(180);

    2. Then again change the direction of the fragment container which is the child of viewpager,

    recyclerView.setRotationY(180);

    Note: In my case, I have used recyclerview as the child of the view pager.

    This is 100% worked for me.

    0 讨论(0)
  • 2020-12-05 15:09

    You can do something like this,

    ViewPager.setCurrentItem(lastposition);
    
    0 讨论(0)
  • 2020-12-05 15:10

    I'm sure it's not relevant for the op, but I found a solution that worked for me (as modifying the data was a problem for my case). I simply rotated the viewpager 180 degrees in the Y axis, and then rotated it's subviews again in 180.

    android.view.View
    
    public void setRotationY(float rotationY)
    

    Hope it helped anyone, as I think this is the most close to how Android mirrors all the os when change to rtl language.

    0 讨论(0)
提交回复
热议问题