美文网首页
viewPager-viewAdapter的使用

viewPager-viewAdapter的使用

作者: kayabu | 来源:发表于2017-08-05 14:51 被阅读0次

viewPager:

  1. public method:
  • setCurrentItem(int item)/setCurrentItem(int item,boolean smoothScroll) : 设置选择的页面

set the currently selected page.

  • setAdapter(PagerAdapter adapter):设置提供views的adapter

set a PagerAdapter that will supply views for this pager as needed.

  • addOnPageChangeListener(OnPageChangeListener):设置动作监听器
  • OnPageChangeListener:
    • onPageScrollStateChanged(int state):页面完全停止或空闲时,发生滑动状态时调用.用于发现用户滑动的时刻
    • onPageScrolled(int position, float positionOffset, int positionOffsetPixels):当前页面被滑动时调用.不管是程序引起的还是用户触发的.
    • onPageSelected(int position):一个新的页面被选中时调用.动画不一定完成.

pageAdapter:

  • 实现一个pageAdapter时,必须重载以下方法:
  1. instantiateItem(ViewGroup,int):在给定位置创建view.可以把view添加此处给出的容器中.

Create the page for the given position. The adapter is responsible for adding the view to the container given here, although it only must ensure this is done by the time it returns from finishUpdate(ViewGroup).

  1. destroyItem(ViewGroup, int, Object):把page从给定位置移出.

Remove a page for the given position. The adapter is responsible for removing the view from its container, although it only must ensure this is done by the time it returns from finishUpdate(ViewGroup)

  1. getCount():返回可用的view数

Return the number of views available.

  1. isViewFromObject(view, Object):判断view是否和一个关键object绑定起来

Determines whether a page View is associated with a specific key object as returned by instantiateItem(ViewGroup, int)

  • 还有两个子类可以实现:
    • FragmentPagerAdapter
    • FragmentStatePagerAdapter
  • notifyDataSetChanged():但view改变时,应该调用此函数!

This method should be called by the application if the data backing this adapter has changed and associated views should update.

相关文章

  • viewPager-viewAdapter的使用

    viewPager: public method: setCurrentItem(int item)/setCur...

  • iconfont的使用(下载使用)

    1、下载文件 2、在生命周期中引入项目 beforeCreate () { var domModule = ...

  • Gson的使用--使用注解

    Gson为了简化序列化和反序列化的过程,提供了很多注解,这些注解大致分为三类,我们一一的介绍一下。 自定义字段的名...

  • 记录使用iframe的使用

    默认记录一下----可以说 这是我第一次使用iframe 之前都没有使用过; 使用方式: 自己开发就用了这几个属...

  • with的使用

    下面例子可以具体说明with如何工作: 运行代码,输出如下

  • this的使用

    什么是this? this是一个关键字,这个关键字总是返回一个对象;简单说,就是返回属性或方法“当前”所在的对象。...

  • this的使用

    JS中this调用有几种情况 一:纯粹的函数调用 这是函数的最通常用法,属于全局性调用,因此this就代表全局对象...

  • ==的使用

    积累日常遇到的编码规范,良好的编码习惯,持续更新。。。 日常使用==用于判断的时候,习惯性将比较值写前面,变量写后...

  • this的使用

    1.默认绑定,就是函数立即执行。 函数立即执行就是指向window,但是如果是node环境,就是指向全局conso...

  • %in% 的使用

    写在前面:From 生信技能书向量难点之一:%in% 难点 (1)== 与 %in% 的区别== 强调位置,x和对...

网友评论

      本文标题:viewPager-viewAdapter的使用

      本文链接:https://www.haomeiwen.com/subject/teoilxtx.html