滑动时Viewpager TabLayout选项卡更改

时间:2018-01-08 05:34:28

标签: android android-viewpager swipe android-tablayout

我希望在用户20%的视图滑动时更改标签但是现在如果我在60左右滑动然后更换标签。其他明智的它回到上一个标签。我怎么能这样做。

   viewPager = (ViewPagerCustomDuration) findViewById(R.id.tabs_viewpager);
        viewPager.setScrollDurationFactor(1);
        viewPager.setOffscreenPageLimit(3);
        viewPager.animate().translationX(0f).setDuration(500);
        final int pageMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, getResources().getDisplayMetrics());
        viewPager.setPageMargin(pageMargin);
        // viewPager.setPagingEnabled(false);
        tabLayout = (TabLayout) findViewById(R.id.tabs);
        tabLayout.setupWithViewPager(viewPager);

        tabFragmentPagerAdapter = new TabFragmentPagerAdapter(getSupportFragmentManager(), MainActivity.this, viewPager);
        tabFragmentPagerAdapter.addFrag(new HomeFragment(), "Home");
        tabFragmentPagerAdapter.addFrag(new DiscoverFragment(), "Discover");
        tabFragmentPagerAdapter.addFrag(new TopFragment(), "Top");
        tabFragmentPagerAdapter.addFrag(new CategoryFragment(), "Category");


        // setupViewPager(viewPager);
        viewPager.setAdapter(tabFragmentPagerAdapter);

enter image description here

0 个答案:

没有答案