我在我的视图中使用谷歌的SlidingTabLayout,但我想动态地添加新的标签。 我使用这个http://developer.android.com/samples/SlidingTabsBasic/src/com.example.android.common/view/SlidingTabLayout.html如何将标签添加到SlidingTabLayout?
这是我的代码初始化:
// 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);
我完全不知道如何添加一个标签。
我想过改变ViewPager但在SlidingTabLayout有一个评论:
/**
* 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) {
这可能与您设想的设计稍有不同,但请看看这个班级 - 它可以做你需要的东西,尽管没有标签:https://github.com/daimajia/AndroidSwipeLayout/ – 2015-02-10 19:22:30
我需要标签。但是,无论如何感谢 – maysi 2015-02-10 19:32:52