How to visible all the time 3 tab on PagerTabStrip?

末鹿安然 提交于 2019-12-07 17:03:45

问题


I have a android application which try to implement android PagerTabStrip on ViewPager.I have three tab 1) Tab1 2)Tab2 and 3) Tab3. When Tab1 are selected then only show Tab1>>Tab2(pic_01).When Tab2 selected then it show Tab1>>Tab2>>Tab3(pic_02). When Tab3 selected then it show Tab2>>Tab3(pic_03).But I want ,all the time 3 tab will be visible at the same time. Such as when Tab1 selected then it will Tab3>>>Tab1>>Tab2. Same as when Tab2 selected then it will be ab1>>Tab2>>Tab3 .and when Tab3 slected then it will be Tab2>>Tab3>>Tab1.My trying cod are bellow which i implement.

   viewPager = (ViewPager) findViewById(R.id.pager);        
    mPagerTabStrip = (PagerTabStrip)findViewById(R.id.PagerTab);
    mPagerTabStrip.setScrollContainer(true);
    // Set the ViewPagerAdapter into ViewPager
    viewPager.setAdapter(new ViewPagerAdapter(getSupportFragmentManager()));

ViewPagerAdapter is the FragmentPagerAdapter class.

public class ViewPagerAdapter extends FragmentPagerAdapter {

final int PAGE_COUNT = 3;
// Tab Titles
private String tabtitles[] = new String[] { "Tab1", "Tab2", "Tab3" };
Context context;

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

@Override
public int getCount() {
    return PAGE_COUNT;
}

@Override
public Fragment getItem(int position) {

    Log.w("position", "are:"+position);
    switch (position) {


        // Open FragmentTab1.java
    case 0:
        FragmentTab1 fragmenttab1 = new FragmentTab1();
        return fragmenttab1;

        // Open FragmentTab2.java
    case 1:
        FragmentTab2 fragmenttab2 = new FragmentTab2();
        return fragmenttab2;

        // Open FragmentTab3.java
    case 2:
        FragmentTab3 fragmenttab3 = new FragmentTab3();
        return fragmenttab3;
    }
    return null;
}

@Override
public CharSequence getPageTitle(int position) {
    return tabtitles[position];
}

}

Actually i want all the time those three tab will be visible same as pic_02.Is it possible?Please help to me.(Thanks to all)


回答1:


Per this answer to a similar question I don't think it is possible with a PagerTabStrip to show all three tabs at the same time (except when on the second tab, of course). It looks like you'll have to use ActionBar or roll your own tab strip.



来源:https://stackoverflow.com/questions/25493840/how-to-visible-all-the-time-3-tab-on-pagertabstrip

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!