how to make my viewpager swipe from right to left

前端 未结 13 624
一整个雨季
一整个雨季 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:26

    For letting your horizontal ViewPager behave like RecyclerView when LayoutDirection change just add this method to your custom ViewPager;

    public class LoopViewPager extends ViewPager {
    ....
    ...
        public void setLayoutDirection(int layoutDirection) {
            if(layoutDirection == ViewCompat.LAYOUT_DIRECTION_LTR) {
                setRotationY(0);
            }
            else if(layoutDirection == ViewCompat.LAYOUT_DIRECTION_RTL) {
                setRotationY(180);
        }
    }
    

    and where you use your viewPager set it dynamically like this;

    viewPager.setLayoutDirection(context.getResources().getConfiguration().getLayoutDirection());
    
    0 讨论(0)
提交回复
热议问题