zoukankan      html  css  js  c++  java
  • Android笔记之ViewPager(一)

    1、概述:

    ViewPager的最大特点就是可以滑动切换页面

    ViewPager的适配器是PagerAdapter,它是基类提供适配器来填充页面ViewPager内部,

    你很可能想要使用一个更具体的实现,如FragmentPagerAdapter或 FragmentStatePagerAdapter。

    在这里需要说明一下,其实ViewPager应该和Fragment一起使用,至少谷歌官方是这么 想的,但是在3.0之下,我们没有必要这么做。下面要注意,当

    你实现一个PagerAdapter,你必须至少覆盖以下方法:

    2、实现步骤:

    主xml文件:

    1、<android.support.v4.view.ViewPager占据了整个屏幕
    <android.support.v4.view.PagerTabStrip占据的是标题
    2、注意事项:   
        1.API中说:在布局xml把PagerTabStrip当做ViewPager的一个子标签来用,不能拿出来,不然还是会报错  
        2.在PagerTabStrip标签中可以用属性android:layout_gravity=TOP|BOTTOM来指定title的位置  
        3.如果要显示出PagerTabStrip某一页的title,需要在ViewPager的adapter中实现getPageTitle(int)
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity" >
    
        <android.support.v4.view.ViewPager
            android:id="@+id/viewPager"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center" >
    
            <android.support.v4.view.PagerTabStrip
                android:id="@+id/pagerTitle"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="top" />
        </android.support.v4.view.ViewPager>
    
    </RelativeLayout>

    2、主代码:

  • 相关阅读:
    如何将DataTable转换成List<T>呢?
    mySql中SUBSTRING_INDEX函数用法
    常用 Git 命令清单
    git学习笔记
    MySql 获取表的字段名
    mysql从身份证号中提取生日、性别
    年月日转大写汉字
    ExtJs服务器端代理(Ajax)
    ExtJS客户端代理
    ExtJS 数据模型
  • 原文地址:https://www.cnblogs.com/xingyyy/p/3322983.html
Copyright © 2011-2022 走看看