更改viewPager滑动方向 [英] Changing viewPager swipe direction

查看:647
本文介绍了更改viewPager滑动方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用TabLayout和viewPager,并带有向左或向右滑动viewPager以便在页面之间导航的选项.

I'm using TabLayout and viewPager with an option to swipe the viewPager to the left or right in order to navigate between pages.

我的问题是,我的应用程序基于RTL(从右到左),并且滑动方向相反.

My problem is, that my application is RTL based (right-to-left) and the swipe direction is reversed.

我正在尝试将滑动方向从默认版本更改为反向版本. 我一直在网上搜索很多东西,却找不到方法.

I'm trying to change the swipe direction from the default to the reversed version. I've been searching alot on the web and couldn't find a way how to do it.

我正在使用android.support.v4.view.ViewPager;

这是我使用viewPager初始化TabLayout的方式:

and this is how I initialize my TabLayout with the viewPager:

// View Page Adapter
        final ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
        final PagerAdapter adapter = new PagerAdapter
                (getSupportFragmentManager(), tabLayout.getTabCount());
        //View Page Adapter Configuration
        viewPager.setAdapter(adapter);
        viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
        viewPager.setOffscreenPageLimit(3);
        tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                viewPager.setCurrentItem(tab.getPosition());
            }

摘要:当前,当我向左滑动viewPager时,它将显示下一页. 在RTL中,当您向右滑动viewPager时,它将显示下一页.

Summary: Currently, When I'm swiping the viewPager to the left, it shows the next page. in RTL, when you swipe the viewPager to the right, it shows the next page.

这可能很难理解,但是确实如此. 向右滑动显示下一页

It might be hard to understand, but here it is. Swiping right shows the next page

我需要向右滑动以显示上一页.

while I need swiping right to show the previous page.

推荐答案

更改Viewpager的滑动方向是非常简单的技术.

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

必须遵循两个简单的步骤,

There are two simple step which have to follow you,

1..更改查看分页器的旋转方式,

1. Change the rotation of the View pager,

viewpager.setRotationY(180);

2..然后再次更改作为viewpager子级的片段容器的方向,

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

recyclerView.setRotationY(180);

注意:在我的情况下,我已将recyclerview用作视图分页器的子级.

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

这对我来说是100%有用的.

This is 100% worked for me.

这篇关于更改viewPager滑动方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆