how to make my viewpager swipe from right to left

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

    my solution. dynamically:

    public class RTLViewPager extends ViewPager {
    
        public RTLViewPager(Context context) {
            super(context);
        }
    
        public RTLViewPager(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
    
        @Override
        public void setAdapter(PagerAdapter adapter) {
            super.setAdapter(adapter);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
                if(getResources().getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL){
                    setCurrentItem(adapter.getCount()-1);
                }
            }
        }
    }
    

提交回复
热议问题