使用ViewPager
with 时PagerTabStrip
:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/pager"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<android.support.v4.view.PagerTabStrip
android:id="@+id/pager_tab_strip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:paddingTop="4dp"
android:paddingBottom="4dp"
/>
</android.support.v4.view.ViewPager>
寻呼机有一个空适配器:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ViewPager pager = (ViewPager) findViewById(R.id.pager);
FragmentPagerAdapter adapter = new FragmentPagerAdapter(getFragmentManager()) {
@Override
public CharSequence getPageTitle(int position) {
return "test";
}
@Override
public Fragment getItem(int i) {
return null;
}
@Override
public int getCount() {
return 0;
}
};
pager.setAdapter(adapter);
}
触摸/滚动标签条时应用程序崩溃:
java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251)
at java.util.ArrayList.get(ArrayList.java:304)
at android.support.v4.view.ViewPager.performDrag(ViewPager.java:1990)
我认为 这条线ViewPager.performDrag()
可能是原因。
我的视图设置是错误还是有问题?