本文介绍了如何将选项卡添加到SlidingTabLayout?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用谷歌的SlidingTabLayout在我看来,但我要动态新的选项卡添加到它。
我使用这个http://developer.android.com/samples/SlidingTabsBasic/src/com.example.android.common/view/SlidingTabLayout.html

这是我的code这初始化:

  //创建一个将返回一个片段为三个的适配器
    //活性的主要部分。
    mSectionsPagerAdapter =新SectionsPagerAdapter(getSupportFragmentManager());
    //这^是FragmentStatePagerAdapter    //设置的ViewPager与部分适配器。
    mViewPager =(ViewPager)findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);    // Assiging滑动标签布局视图
    标签=(SlidingTabLayout)findViewById(R.id.tabs);    //设置ViewPager对于SlidingTabsLayout
    tabs.setViewPager(mViewPager);

我完全不知道如何添加一个标签。

我想过改变ViewPager但在SlidingTabLayout有一个评论:

  / **
 *设置相关的观点寻呼机。需要注意的是这里的假设是,该寻呼机内容
 *(选项卡和选项卡标题的数量)这一呼吁作出后不会改变。
 * /
公共无效setViewPager(ViewPager viewPager){


解决方案

有可能是一个更好的,更有效的方式,而只是调用 setViewPager()每次添加一个页面的 ViewPager 将工作。

I am using google's SlidingTabLayout in my view, but i want to add dynamically new tabs to it.I'm using this http://developer.android.com/samples/SlidingTabsBasic/src/com.example.android.common/view/SlidingTabLayout.html

This is my code which initialize it:

    // Create the adapter that will return a fragment for each of the three
    // primary sections of the activity.
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
    //this ^ is a FragmentStatePagerAdapter

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);

    // Assiging the Sliding Tab Layout View
    tabs = (SlidingTabLayout) findViewById(R.id.tabs);

    // Setting the ViewPager For the SlidingTabsLayout
    tabs.setViewPager(mViewPager);

I have absolutely no idea how to add a Tab.

I thought about changing the ViewPager but in the SlidingTabLayout there is a comment:

/**
 * Sets the associated view pager. Note that the assumption here is that the pager content
 * (number of tabs and tab titles) does not change after this call has been made.
 */
public void setViewPager(ViewPager viewPager) {
解决方案

There's probably a nicer, more efficient way, but simply calling setViewPager() every time you add a page to your ViewPager will work.

这篇关于如何将选项卡添加到SlidingTabLayout?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-16 05:34