Mars视频笔记——Animation
Animations的使用(1)
什么是Animations
提供了一系列的动画效果,可以应用在绝大多数控件中
Animations的分类
1 Tweened Animations 渐变动画
提供了旋转,移动,伸展,淡出等效果
2 Frame-by-Frame Animations
可以创建一个Drawable序列,按照指定时间间歇一个个显示
Tweened Animations:
1 Alpha 淡入淡出效果
2 Scale 缩放效果
3 Rotate 旋转效果
4 Translate 移动效果
Animations的第一种使用方法(代码实现,xml实现)
使用Tweened Animations的步骤:
1 创建一个AnimationSet对象
AnimationSet animationSet=new AnimationSet(true);
2 根据需要创建相应的Animation对象(旋转,移动,伸展,淡出)
AlphaAnimation alphaAnimation = new AlphaAnimation(1,0); //参数为from..to..
*其他:
RotateAnimation rotateAnimation = new RotateAnimation(0,360,Animation.RELATIVE_TO_PARENT(有3 种),1f,Animation.RELATIVE_TO_PARENT,0f);
3种坐标种类Animation.RELATIVE_TO_SELF,Animation.RELATIVE_TO_PARENT,Animation.ABSOLUTE
ScaleAnimation scaleAnimation = new ScaleAnimation(1,0.1f,1,0.1f,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
TranslateAnimation .......
3 根据软件动画的需求,为Animation对象设置相应数据
animationSet.setDuration(1000); //动画执行时间
4 将Animation对象添加到AnimationSet对象中
animationSet.addAnimation(alphaAnimation);
5 使用控件对象开始执行AnimationSet
imageView.startAnimation(animationSet);
Tweened Animations 通用属性
setDuration
setFillAfter
SetFillBefore
setStartOffSet
setRepeatCount
Animations使用(2)
接上篇
Animations的第二种使用方法(第一种见1)
步骤:
1 在res文件夹线面新建一个名为anim的文件夹
2 创建xml文件,并首先加入set标签,改标签如下
- <setxmlns:android="http://schemas.android.com/apk/res/android"
- android:interpolator="@android:anim/accelerate_interpolator">
- ...
- </set>
3 在该标签中加入rotate,alpha,scale或者translate标签
例:
Alpha的alpha.xml文件编写方法(这些标签都是放在set标签中的)
- <alphaandroid:fromAlpha="1.0"
- android:toAlpha="0.0"
- android:atartOffset="500"
- android:duration="500"/>
rotate.xml
- <rotateandroid:fromDegrees="0"
- android:toDegrees="+350" //正350度
- android:pivotX="50%"
- android:pivotY="50%"
- android:duration="3000"/>
这里要特别注意跟位置有关的参数pivotX和pivotY
3种写法对应3种相对位置方式的设置方式:
android:pivotX="50" 绝对定位
android:pivotX="50%" 相对于控件本身
android:pivotX="50%p" 相对于父控件
translate.xml
- <translateandroid:fromXDelta="50%"
- android:toXDelta="100%"
- android:fromYDelta="0%"
- android:toYDelta="100%"
- android:duration="1000"/>
scale.xml
- <scaleandroid:fromXScale="1.0"
- android:toXScale="0.0"
- android:fromYScale="1.0"
- android:toYScale="0.0"
- android:pivotX="50%"
- android:pivotY="50%"
- android:duration="2000"/>
4 在代码中使用AnimationUtils装载xml文件,并生成Animation对象
- Animation animation=AnimationUtils.loadAnimation(MainActivity.this, R.anim.alpha); //载入布局文件
- imageView.startAnimation(animation);
Animations的使用(3)
1 AnimationSet的使用方法
什么是AnimationSet
1 AnimationSet是Animation的子类
2 一个AnimationSet包含了一系列的Animation
3 针对AnimationSet设置一些Animation的常见属性(如StartOffset,duration等),可以被包含在AnimationSet当中的Animation继承
使用步骤:(类似1中的例子 只不过含有2个动画效果)
- AnimationSet animationSet = new AnimationSet(ture);
- AlpahaAnimation alpha = new AlphaAnimation(...);
- RotateAnimation rotate = new RotateAnimation(...);
- animationSet.addAnimation(alpha);
- animationSet.addAnimaion(rotate);
- animationSet.setDuration(2000);
- animationSet.setStartOffset(500);
- imageView.startAnimation(animationSet);
2 Interpolator的使用方法
Interpolator定义了动画变化速率,在Animations框架中定义了以下几种Interpolator
AccelerateDecelerateInterpolator:在动画开始和结束的地方速率变化较慢,中间的时候加速
AccelerateInterpolator:在动画开始的地方速率改变较慢,然后加速
CycleInterpolator:动画循环播放特定次数,速率改变沿正弦曲线
DecelerateInterpolator:在动画开始的地方速率改变较慢,然后减速
LinearInterpolator:以均匀的速率改变
设置的地方就在set标签中的 android:interpolator="@android:anim/accelerate_interpolator"
而之后还有一个android:shareInterpolator="true" 从名字就可以看到这是为set中所有的动画设置Interpolator
如果要单独设置 则将shareInterpolator设为false 然后为每个动画中单独定义Interpolator
以上是在xml中设置,如果要在代码中设置
animationSet.setInterpolator(new AccelerateInterpolator());(也可以单独设置)
注意在AnimationSet的构造方法中有一个boolean参数,这个参数就是shareInterpolator的设定
3 Frame-By-Frame Animations的使用方法
1 在res/drawable中创建一个xml文件,定义Animation的动画播放序列 anim_nv.xml
- <animation-listxmlns:android="http://schemas.android.com/apk/res/android"
- android:oneshot="false">
- <itemandroid:drawable="@drawable/nv1"
- android:duration="500"/>
- <itemandroid:drawable="@drawable/nv2"
- android:duration="500"/>
- <itemandroid:drawable="@drawable/nv3"
- android:duration="500"/>
- <itemandroid:drawable="@drawable/nv4"
- android:duration="500"/>
- </animation-list>
2 为ImageView设置背景资源
- imageView.setBackgroundResource(R.drawable.anim_nv);
3 通过ImageView得到AnimationDrawable
- AnimationDrawable animationDrawable = (AnimationDrawable) imageView.getBackground();
3 执行动画
- animationDrawable.start();
Animations使用(4)
LayoutAnimationController的使用方法(与ListView结合使用为例)
什么是LayoutAnimationController
1 LayoutAnimationController用于为一个layout里面的控件,或者是一个ViewGroup里面的控件设置动画效果
2 每一个控件都有相同的动画效果
3 这些控件的动画效果在不同的时间显示出来
4 LayoutAnimationController可以在xml文件中设置,也可以在代码中设置
在XML中使用LayoutAnimaionController
1 在res/anim文件夹中创建一个文件,名为list_anim_layout.xml
- <layoutAnimationxmlns:android="http://schemas.android.com/apk/res/android"
- android:delay="0.5"
- android:animationOrder="random"
- android:animation="@anim/list_anim"/>
注意到list_anim这个xml文件,其中配置了动画效果,也就是一个动画配置文件(见3中)
<set>
<alpha...>
</set>
2 在布局文件中为ListView添加如下配置(就是在<listview>标签中添加一个属性)
android:layoutAnimation="@anim/list_anim_layout"
在代码中使用LayoutAnimationController
- 1 创建一个Animation对象:
- 可以通过装载xml,也可以直接使用Animation的构造函数创建Animation对象
- 2 创建LayoutAnimationController对象
- LayoutAnimationController lac=new LayoutAnimationController(animation);
- 3 设置控件显示顺序
- lac.setOrder(LayoutAnimationController.ORDER_NORMAL);
- 4 为ListView设置LayoutAnimationController属性:
- listView.setLayoutAnimation(lac);
AnimationListener的使用方法
什么是AnimationListener
1 Animation是一个监听器
2 该监听器在动画执行的各个阶段会得到通知,从而调用相应的方法
3 主要包含下面的三个方法
onAnimationEnd(Animation animation)
onAnimationRepeat(Animation animation)
onAnimationStart(Animation animation)
使用方法:
animation.setAnimationListener(new XxxAnimationListener);
其中XxxAnimationListener继承AnimationListene
在其中实现三个onXXX方法
Mars视频笔记——Animation的更多相关文章
- ng机器学习视频笔记(一)——线性回归、代价函数、梯度下降基础
ng机器学习视频笔记(一) --线性回归.代价函数.梯度下降基础 (转载请附上本文链接--linhxx) 一.线性回归 线性回归是监督学习中的重要算法,其主要目的在于用一个函数表示一组数据,其中横轴是 ...
- ng机器学习视频笔记(二) ——梯度下降算法解释以及求解θ
ng机器学习视频笔记(二) --梯度下降算法解释以及求解θ (转载请附上本文链接--linhxx) 一.解释梯度算法 梯度算法公式以及简化的代价函数图,如上图所示. 1)偏导数 由上图可知,在a点 ...
- ng机器学习视频笔记(十六) ——从图像处理谈机器学习项目流程
ng机器学习视频笔记(十六) --从图像处理谈机器学习项目流程 (转载请附上本文链接--linhxx) 一.概述 这里简单讨论图像处理的机器学习过程,主要讨论的是机器学习的项目流程.采用的业务示例是O ...
- 斯坦福机器学习视频笔记 Week1 Linear Regression and Gradient Descent
最近开始学习Coursera上的斯坦福机器学习视频,我是刚刚接触机器学习,对此比较感兴趣:准备将我的学习笔记写下来, 作为我每天学习的签到吧,也希望和各位朋友交流学习. 这一系列的博客,我会不定期的更 ...
- 慕课网,vue高仿饿了吗ASP源码视频笔记
1.源码笔记 我的源码+笔记(很重要):http://pan.baidu.com/s/1geI4i2Z 感谢麦子学院项目相关视频 2.参考资料 Vue.js官网(https://vuejs.org.c ...
- 斯坦福机器学习视频笔记 Week1 线性回归和梯度下降 Linear Regression and Gradient Descent
最近开始学习Coursera上的斯坦福机器学习视频,我是刚刚接触机器学习,对此比较感兴趣:准备将我的学习笔记写下来, 作为我每天学习的签到吧,也希望和各位朋友交流学习. 这一系列的博客,我会不定期的更 ...
- 无限互联IOS电影项目视频笔记
下面是该iOS项目视频教程的内容大纲: 观看指南 (1)项目为第一阶段内容 (2)需要熟练掌握OC语言 (3)UI部分需要学习到第十节课 (4)项目适合刚入门的iOS开发者 1.第一天 (1)iOS ...
- 一名测试初学者听JAVA视频笔记(一)
搭建pho开发环境与框架图 韩顺平 第一章: No1 关于文件以及文件夹的管理 将生成的文本文档做成详细信息的形式,显示文件修改时间以及文件大小,便于文件查看和管理,也是对于一名IT人士高效能工作的 ...
- angular2 学习笔记 ( animation 动画 )
refer : https://angular.io/guide/animations https://github.com/angular/angular/blob/master/packages/ ...
随机推荐
- idea+Spring+Mybatis+jersey+jetty构建一个简单的web项目
一.先使用idea创建一个maven项目. 二.引入jar包,修改pom.xml <dependencies> <dependency> <groupId>org. ...
- CODING 告诉你如何建立一个 Scrum 团队
原文地址:https://www.atlassian.com/agile/scrum/roles 翻译君:CODING 敏杰小王子 Scrum 当中有三个角色:PO(product owner),敏捷 ...
- 【CodeForces - 1200A】Hotelier(水题、模拟)
Hotelier 直接翻译了 Descriptions Amugae的酒店由10人组成10客房.房间从0开始编号0到99 从左到右. 酒店有两个入口 - 一个来自左端,另一个来自右端.当顾客通过左入口 ...
- exe、dos、bat等静默运行,后台运行,不弹窗的解决办法
exe中 #pragma comment( linker, "/subsystem:windows /entry:mainCRTStartup" ) 1. WinExec(LPCS ...
- 学习Canvas这一篇文章就够了
一.canvas简介 <canvas> 是 HTML5 新增的,一个可以使用脚本(通常为JavaScript)在其中绘制图像的 HTML 元素.它可以用来制作照片集或者制作简单(也不是 ...
- (三十二)c#Winform自定义控件-表格
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...
- loging日志的使用
2.日志: 记住怎么使用就好了 自己定义日志开始 import logging logger = logging.getLogger() # 创建一个logger fh = logging.FileH ...
- Vue + TypeScript + Element 搭建简洁时尚的博客网站及踩坑记
前言 本文讲解如何在 Vue 项目中使用 TypeScript 来搭建并开发项目,并在此过程中踩过的坑 . TypeScript 具有类型系统,且是 JavaScript 的超集,TypeScript ...
- Windos 上逆天又好用的软件有哪些?
谷歌浏览器 Chrome 浏览器是大名鼎鼎的科技公司谷歌开发的一款浏览器,国内的360浏览器等大多都是基于谷歌开源出的浏览器内核,然后给他穿了一层360的衣服.至于性能和启动速度上来讲,我个人觉得Ch ...
- 企查查app 初步探索
企查查app sign算法破解初步探索 之前有说过企查查的sign的解密,但这次是企查查app的sign算法破解,目前是初步进程. 已删除!!!! 上边一些变量已经找到了,其中就有时间戳,其余两个需要 ...