组合选项卡布局和选项卡滑动

时间:2016-05-01 20:27:51

标签: android android-tablayout

我已经实现了标签布局,但是当我添加标签滑动时。它冻结我不能使用选项卡布局中的其他选项卡。任何建议。

这是我的标签布局代码

public class TabLayoutAdmin extends TabActivity {

private TabHost mTabHost;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tablayoutadmin);
    Resources res= getResources();
    TabHost tabHost = getTabHost();

    Intent confirmedList = new Intent().setClass(this, Reservations.class);
    TabHost.TabSpec tabSpecConfirmedList= tabHost
            .newTabSpec("Android")
            .setIndicator("", res.getDrawable(R.drawable.stadimumspage))
            .setContent(confirmedList);


    Intent stadiumsPage = new Intent().setClass(this, StadiumsPage.class);
    TabHost.TabSpec tabSpecStadiumsPage = tabHost
            .newTabSpec("Apple")
            .setIndicator("", res.getDrawable(R.drawable.newreservation))
            .setContent(stadiumsPage);

    Intent newReservation = new Intent().setClass(this, NewReservation.class);
    TabHost.TabSpec tabSpecNewReservation= tabHost
            .newTabSpec("Windows")
            .setIndicator("", res.getDrawable(R.drawable.confirmedlist))
            .setContent(newReservation);


    Intent blockTeam = new Intent().setClass(this, Block_Team.class);
    TabHost.TabSpec tabSpecBlockTeam = tabHost
            .newTabSpec("Berry")
            .setIndicator("", res.getDrawable(R.drawable.blockteam))
            .setContent(blockTeam);

    // add all tabs
    tabHost.addTab(tabSpecConfirmedList);
    tabHost.addTab(tabSpecStadiumsPage);
    tabHost.addTab(tabSpecNewReservation);
    tabHost.addTab(tabSpecBlockTeam);

    //set Windows tab as default (zero based)
    tabHost.setCurrentTab(0);
}

至于标签滑动,我使用了这段代码 http://www.androidhive.info/2013/10/android-tab-layout-with-swipeable-views-1/

由于

1 个答案:

答案 0 :(得分:0)

您应该使用TabLayout来保存片段和ViewPager以进行滑动,以下是如何逐步执行此操作:tablayout with viewpager