您的位置:首页 > 其它

ViewPager 二个子控件PagerTabStrip与PagerTitleStrip添加标题栏

2014-11-29 17:43 441 查看
在android.support.v4包中的两个控件PagerTabStrip与PagerTitleStrip,他们都是用来实现标题栏的,但各自有些不同,在这篇文章中,我们就讲讲它们各自都能实现怎样的功能,又有哪些异同点。

一、PagerTabStrip

PagerTabStrip的官方解释:


Class Overview

PagerTitleStrip is a non-interactive indicator of the current, next, and previous pages of a
ViewPager
.
It is intended to be used as a child view of a ViewPager widget in your XML layout. Add it as a child of a ViewPager in your layout file and set its android:layout_gravity to TOP or BOTTOM to pin it to the top or bottom of the ViewPager. The title from each
page is supplied by the method
getPageTitle(int)
in
the adapter supplied to the ViewPager.

For an interactive indicator, see
PagerTabStrip
.
翻译:PagerTitleStrip是ViewPager的一个关于当前页面、上一个页面和下一个页面的一个非交互的指示器。它经常作为ViewPager控件的一个子控件添加在XML布局文件中。在你的布局文件中,将它作为子控件添加在ViewPager中。而且要将它的
android:layout_gravity 属性设置为TOP或BOTTOM来将它显示在ViewPager的顶部或底部。每个页面的标题是通过适配器的getPageTitle(int)函数提供给ViewPager的。
总结起来 2点

1、在你的布局文件中,将它作为子控件添加在ViewPager中。

如:

<ViewPager>

<PagerTabStrip>

</PagerTabStrip>

</ViewPager>

2、标题的获取,是重写适配器的getPageTitle(int)方法来获取的。

一个例子

仅仅是 布局不同 一个有下划线 一个没有滑动的下划线

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity" >

    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
<pre name="code" class="html">//<android.support.v4.view.Pager<span style="font-family:FangSong_GB2312;">Title</span>Strip<span style="font-family:FangSong_GB2312;">></span>
<android.support.v4.view.PagerTabStrip 
android:id="@+id/pagerTabStrip" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content"
 android:layout_gravity="top" />
 </android.support.v4.view.ViewPager>
</LinearLayout>



效果图

PagerTabStrip---<span style="color:#0660;"><span style="font-family:FangSong_GB2312;">滑动下划线</span></span>




PS:PagerTabStrip和PagerTitleStrip都不适合用在实际用途中
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐