how to reverse the direction of viewPager to left to right order?

后端 未结 3 1965
孤城傲影
孤城傲影 2020-12-03 23:17

I have viewPager with several views. the default behavior of viewPager is that the first item is displayed first, then swiping right to left displays the second view right t

相关标签:
3条回答
  • 2020-12-03 23:44

    You can simply use setCurrentItem() to navigate to the last page in the ViewPager when it's attached to the View.

    0 讨论(0)
  • 2020-12-03 23:49

    why don't you reverse the list of you view in view pager and use setCurrentItem(int) or setCurrentItem(int,boolean) and set the last one at the launch of the activity/fragment..

    0 讨论(0)
  • 2020-12-03 23:50

    you can now show items horizontally in Recyclerview.

    There have an option to show recyclerview items as reverse order.

    RecyclerView recyclerView = findViewById(R.id.recyclerView);
    recyclerView.setLayoutManager(new LinearLayoutManager(activity, LinearLayoutManager.HORIZONTAL, true)); // last parameter is isReverse
    

    If you want to show RecyclerView items like ViewPager paging you should to use this library:

    https://github.com/lsjwzh/RecyclerViewPager

    This codes will show RecyclerView as Reverse Order ViewPager.

    Here is the code:

    RecyclerViewPager recyclerViewPager = findViewById(R.id.recyclerViewPager);
    recyclerViewPager.setLayoutManager(new LinearLayoutManager(activity, LinearLayoutManager.HORIZONTAL, true));
    
    
    repositories {
        ...
        maven { url "https://jitpack.io" }
        ...
    }
    
    dependencies {
        ...
        compile 'com.github.lsjwzh.RecyclerViewPager:lib:v1.1.2@aar'
        ...
    }
    
    0 讨论(0)
提交回复
热议问题