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

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 methodgetPageTitle(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都不适合用在实际用途中

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值