两个标签之间的中心标志

时间:2017-10-21 14:22:17

标签: android tabs imageview android-tablayout tabview

Here the vector of what i'm trying to do

这两个标签之间会有2个标签和一个图像视图,并且标识应该是不可点击的。

我几乎尝试了所有方法,但都失败了。

任何知道怎么做的人?

代码:

        TabLayout tabLayout = (TabLayout) view.findViewById(R.id.tabs2);
        tabLayout.setupWithViewPager(mViewPager);
        tabLayout.getTabAt(1).setIcon(R.drawable.logo);



    }

    public class SectionsPagerAdapter extends FragmentPagerAdapter {

        public SectionsPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {

            switch (position) {
                case 0:

                    return new LeaderBoard();

                case 1:

                    return new Logo();

                case 2:

                    return new Recent_Post();

                default:

                    return null;
            }

        }

        @Override
        public int getCount() {
            // Show 3 total pages.
            return 3;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            switch (position) {
                case 0:
                    return "LeaderBoard";
                case 1:
                    return "";
                case 2:
                    return "Recent Posts";
            }
            return null;
        }
    }

1 个答案:

答案 0 :(得分:1)

我通过在彼此之间切换标签解决了我的问题,一些计算。

int currentScreen = 0;

mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            }

            @Override
            public void onPageSelected(int position) {
                if (position == 1) {
                    if(currentScreen == 0) {
                        mViewPager.setCurrentItem(2);
                        currentScreen = 2;
                    }else{
                        mViewPager.setCurrentItem(0);
                        currentScreen = 0;
                    }
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {
            }
        });