如果我只是向您展示,而不是解释问题,会容易得多:
如您所见,选项卡标题全部混合在一起并且完全没有样式。它们在通过切换选项卡滑动时正常工作(尽管除了在适当的位置移动之外没有可见的指示)并点击选项卡切换视图,但所有样式都丢失了。这是代码:
画廊列表.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<com.viewpagerindicator.TabPageIndicator
android:id="@+id/indicator"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<android.support.v4.view.ViewPager
android:id="@+id/gallerypager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
GalleryLists.java
public class GalleryLists extends Activity {
Context context;
private static final String[] titles = new String[] {
"20 Hottest", "20 Worst", "20 Awesomest", "MMA", "Comedy", "Moto", "Games" };
ViewPager listPager;
ListPagerAdapter listPagerAdapter;
PageIndicator indicator;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gallerylists);
context = this;
listPagerAdapter = new ListPagerAdapter();
ViewPager.OnPageChangeListener changeListener = new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int i, float v, int i1) {}
@Override
public void onPageSelected(int i) {}
@Override
public void onPageScrollStateChanged(int i) {}
};
listPager = (ViewPager) findViewById(R.id.gallerypager);
listPager.setAdapter(listPagerAdapter);
listPager.setOnPageChangeListener(changeListener);
indicator = (TabPageIndicator) findViewById(R.id.indicator);
indicator.setViewPager(listPager);
indicator.setOnPageChangeListener(changeListener);
}
private class ListPagerAdapter extends PagerAdapter {
// Not important (I believe)
}
}
就是这样。现在,除非我在阅读文档和检查示例时感到非常困惑,否则我不应该采取任何额外的步骤来使用默认样式。我有点不知所措。