相信很多開發者朋友使用過ViewPager這個類,這個類在使用時必須在項目中添加android-support-v4.jar這個類包。
在xml中引用時必須要寫全包名,否則無法找到此類。
舉例如下:
- <android.support.v4.view.ViewPager
- android:id="@+id/viewpager"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:layout_gravity="center" >
- <android.support.v4.view.PagerTitleStrip
- android:id="@+id/pagertitle"
- android:layout_width="fill_parent"
- android:layout_height="45dp"
- android:layout_gravity="top"
- android:visibility="gone" />
- <android.support.v4.view.PagerTabStrip
- android:id="@+id/pagertab"
- android:layout_width="fill_parent"
- android:layout_height="45dp"
- android:layout_gravity="top" />
- </android.support.v4.view.ViewPager>
這裏面有兩個控件PagerTitleStrip和PagerTabStrip,這兩個控件必須當作ViewPager的子控件來用,否則會報錯。
那這兩個控件有什麼區別呢?
其實區別很簡單,官方文檔上寫着:
PagerTabStrip:PagerTabStrip
is an interactive indicator of the current, next, and previous pages of a ViewPager
.
PagerTitleStrip:PagerTitleStrip
is a non-interactive indicator of the current, next, and previous pages of a ViewPager
.
簡單的理解就是:
PagerTabStrip:交互式
PagerTitleStrip:非交互式
經過簡單測試發現:
PagerTabStrip:
1.點擊上面的標題可以實現ViewPager的切換。
2.選中的文字下方包含指引線
3.可是設置是否顯示全寬下劃線(setDrawFullUnderline)
PagerTitleStrip:
1.點擊上面的標題無反應。
2.無上述描述。