Home >Web Front-end >HTML Tutorial >PagerTitleStrip PagerTabStrip ViewPager's page title_html/css_WEB-ITnose under the Android v4 package

PagerTitleStrip PagerTabStrip ViewPager's page title_html/css_WEB-ITnose under the Android v4 package

WBOY
WBOYOriginal
2016-06-24 11:47:291187browse

1. Add the android support package

Because several classes are provided in the android support package, we first add the android-support-v4.jar file to the libs of the project Just go to the directory.

2. activity_main.xml


android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > ;

                                                                                                                                                                                                                                       xml uses PagerTabStrip as a sub-tag of ViewPager and cannot be taken out, otherwise an error will still be reported
3. In the PagerTabStrip tag, you can use the attribute android:layout_gravity=TOP|BOTTOM to specify the position of the title
4. If To display the title of a page in PagerTabStrip, you need to implement getPageTitle(int)
in the ViewPager adapter -->

android: id="@ id/view_pager"
                                                                                        use using id ‐ ‐ ‐ ‐ ‐ ‐ ‐ android: t ;

                                                     android:layout_height="wrap_content "
                                                                                  android: -
                                                                                      ’ s ’ s ’s ’ s ’ s ’ t         ’ ‐ to ’s ’ ’ s ‐ ‐ ‐ ‐ ‐ and android:layout_height="45dp" ​
                                                                                                       android:layout_gravity = "Bottom"
Android: Visibility = "Gone"/& GT; elayout & gt ;



There are two controls, PagerTitleStrip and PagerTabStrip, which must be used as sub-controls of ViewPager, otherwise an error will be reported.

What is the difference between the two controls?

The simple understanding is:

PagerTabStrip: interactive

PagerTitleStrip: non-interactive

After a simple test, it was found:

PagerTabStrip :

① Click the title above to switch ViewPager.

② The selected text contains a guideline below

③ Display full-width underline (setDrawFullUnderline)

PagerTitleStrip:

① Clicking on the title above does not respond.

② No above description.

3. Set the title value

PagerAdater has a getPageTitle, which needs to be rewritten, and then different titles can be returned according to different pages

private class MyPagerAdapter extends PagerAdapter {

@Override
public int getCount() {
return mImageListView.size();
}


@Override
public boolean isViewFromObject(View arg0, Object arg1) {
return arg0 == arg1;
}


@Override
public Object instantiateItem(ViewGroup container, int position) {
container.addView(mImageListView.get(position));
return mImageListView.get(position);
}

@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView(mImageListView.get(position));
}


@Override
public CharSequence getPageTitle(int position) {
switch (position) {
case 0:
return "页面0";
case 1:
return "页面1";
case 2:
return "页面2";
case 3:
return "页面3";
}
return super.getPageTitle(position);
}
}


效果如下:



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn