0
我想創建一個類似android市場的選項卡。Android市場選項卡沒有分段的效果
我發現了一個教程在這裏做它:https://github.com/JakeWharton/Android-ViewPagerIndicator
我的問題是,我不希望使用碎片(因爲他們沒有從舊的是2.3的Android支持),但activities.Is這可能嗎?
這是我的代碼:
public class Activity extends FragmentActivity {
private PagerAdapter mPagerAdapter;
static final String[] CONTENT = new String[] { "categories", "Featured",
"Top Paid", "Top Free", "Top Grossing", "Top New Paid",
"Top New Free", "Trending", "Staff choices", "Editor's Choices" };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.setContentView(R.layout.simple_tabs);
// initialize the pagerz
this.initialisePaging();
}
/**
* Initialize the fragments to be paged
*/
private void initialisePaging() {
List<Fragment> fragments = new Vector<Fragment>();
fragments.add(Fragment.instantiate(this, frag3.class.getName()));
fragments.add(Fragment.instantiate(this, frag4.class.getName()));
fragments.add(Fragment.instantiate(this, frag0.class.getName()));
fragments.add(Fragment.instantiate(this, frag0.class.getName()));
fragments.add(Fragment.instantiate(this, frag0.class.getName()));
fragments.add(Fragment.instantiate(this, frag0.class.getName()));
fragments.add(Fragment.instantiate(this, frag0.class.getName()));
fragments.add(Fragment.instantiate(this, frag0.class.getName()));
fragments.add(Fragment.instantiate(this, frag0.class.getName()));
fragments.add(Fragment.instantiate(this, frag0.class.getName()));
fragments.add(Fragment.instantiate(this, frag0.class.getName()));
this.mPagerAdapter = new FragmentPagerAdapter2(super
.getSupportFragmentManager(), fragments);
ViewPager pager = (ViewPager) super.findViewById(R.id.pager);
pager.setAdapter(this.mPagerAdapter);
pager.setCurrentItem(1);
TabPageIndicator indicator = (TabPageIndicator) findViewById(R.id.indicator);
indicator.setViewPager(pager);
indicator.setCurrentItem(1);
}
}