打造绚丽的ViewPager
2016-05-22 16:48
253 查看
打造绚丽的ViewPager
标签: Android对于ViewPager,我们都很熟悉,这个空间Google已为我们封装好,我们只需要简单的使用就可以,但是默认情况下就是一个水平移动的效果,过于单调,今天来学习下如何打造绚丽的ViewPager,实现动画效果。
just do it!
其实Google已经为我们提供了这样一个动画接口,我们只需要实现这个接口,然后编写我们需要的动画就可以了./** * A PageTransformer is invoked whenever a visible/attached page is scrolled. * This offers an opportunity for the application to apply a custom transformation * to the page views using animation properties. * * <p>As property animation is only supported as of Android 3.0 and forward, * setting a PageTransformer on a ViewPager on earlier platform versions will * be ignored.</p> */ public interface PageTransformer { /** * Apply a property transformation to the given page. * * @param page Apply the transformation to this page * @param position Position of page relative to the current front-and-center * position of the pager. 0 is front and center. 1 is one full * page position to the right, and -1 is one page position to the left. */ public void transformPage(View page, float position); }
这个接口是在ViewPager内部的私有接口,这个是Google官方的源码,对于开发的我们来说,小小的注释肯定是难不倒我们的,我们都懂得哈!
在此附上一篇很详细的讲解transformPage()方法的两个参数的文章,也省的我在绘图了。 蹦跶的小码哥,这篇文章通俗易懂,so easy!!
然后就是为ViewPager实现这个接口了,真的是很简单,一行代码就搞定,
ViewPager.setPageTransformer()方法就欧拉!!
mViewPager = (ViewPager) findViewById(R.id.vp); mViewPager.setPageTransformer(true,mTransformer); ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager()); mViewPager.setAdapter(adapter);
源码在此!!
一个实现了几个简单动画效果的ViewPager的源码
相关文章推荐
- 0 1 背包问题
- 2016"百度之星" - 初赛(Astar Round2B)
- php数组----初探谈任何语言恒古不变的是算法和思想谈与Java中的数组对比
- EventBus3.0使用
- 在jQueryEasyui datagrid加载完成后清除选中
- cookie 和 session
- 【BZOJ-2115】Xor 线性基 + DFS
- Python 资源大全中文版
- POJ 1276 多重背包+模板
- C++变量和对象的区别联系
- Android进程间通信(IPC)之Socket
- Android之记住密码与自动登陆实现
- web前端新手需要认识的CSS;css共有多少标签呢?
- Cube Stacking
- 软件工程个人作业12
- linux的脚本应用for循环答应变量
- Navicat连接Oracle11g 错误的解决办法
- Action属性值决定物理视图资源
- PAT螺旋方阵
- 反转一个单链表并输出