动画学习 五
来源:互联网 发布:知更 杨千嬅试听 编辑:程序博客网 时间:2024/06/02 05:46
一)使用LayoutTranistion制作布局过渡动画
使用布局过渡动画的ViewGroup中的view分为两类:
1)通过调用setVisibility()方法从ViewGroup中添加或去除的View,这类View使用显示(appearing)和消失过渡动画(disappearing).
2)剩余View,这类View在上一类View发生改变时,也会使用相应的过渡动画(因显示引起布局改变的过渡动画和因消失引起布局改变的过渡动画)来移动到新的位置。
如果使用系统默认的布局过渡动画的话,只需设置android:animateLayoutchanges属性为true即可。在XML中为ViewGroups提供默认的布局过渡动画.如:
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/verticalContainer"
android:animateLayoutChanges="true" />
也可以自定义过渡动画,调用LayoutTransiton对象的setAnimator()方法,在该方法中传入如下参数之一和一个Animator对象:
APPEARING - 标识该动画在容器(ViewGroup)中正在显示的View上运行。
CHANGE_APPEARING - 标识该动画在容器(ViewGroup)中因新View出现而引起改变的其他View上运行。
DISAPPEARING - 标识该动画在容器(ViewGroup)中正在消失的View上运行。A flag indicating the animation that runs onitems that are disappearing from the container.
CHANGE_DISAPPEARING - 标识该动画在容器(ViewGroup)中因莫View消失而引起改变的其他View上运行。
在代码中,使用ViewGroups的setLayoutTransition(LayoutTransition transition)方法来设置该ViewGroup采用某过渡动画。
二)指定关键帧(Keyframes)
Keyframe对象包含一个时间/值对,可以用来指定动画中特定时间的状态。每个keyframe还可以拥有自己的插值器来控制前一个keyframe与该frame之间的时间间隔中的动画行为。
可以通过使用Keyframe的工厂方法ofInt(),ofFloat()或ofObject()来获取Keyframe实例。 然后使用ofKeyframe()方法获得一个PropertyValuesHolder对象, 然后将该对象和动画目标对象作为参数传给ofPropertyValuesHoder来获取Animator对象。例子如下:
Keyframe kf0 = Keyframe.ofFloat(0f,0f);
Keyframe kf1 =Keyframe.ofFloat(.5f,360f);
Keyframe kf2 =Keyframe.ofFloat(1f,0f);
PropertyValuesHolder pvhRotation = PropertyValuesHolder.ofKeyframe("rotation", kf0, kf1, kf2);
ObjectAnimator rotationAnim = ObjectAnimator.ofPropertyValuesHolder(target, pvhRotation)
rotationAnim.setDuration(5000ms);
三)使用ViewPropertyAnimator来制作动画
ViewPropertyAnimator提供了一种简单的方法来对View的多个属性同时播放动画。 与ObjectAnimator类似,在同时操作多个属性时更方便,代码也更简洁。下面是与使用多个ObjectAnimator, 使用一个ObjectAnimator和使用ViewPropertyAnimator同时操作View的x值和y值的比较:
Multiple ObjectAnimatorobjects
ObjectAnimator animX = ObjectAnimator.ofFloat(myView,"x",50f);
ObjectAnimator animY = ObjectAnimator.ofFloat(myView,"y",100f);
AnimatorSet animSetXY = new AnimatorSet();
animSetXY.playTogether(animX, animY);
animSetXY.start();
One ObjectAnimator
PropertyValuesHolder pvhX = PropertyValuesHolder.ofFloat("x",50f);
PropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat("y",100f);
ObjectAnimator.ofPropertyValuesHolder(myView, pvhX, pvyY).start();
ViewPropertyAnimator
myView.animate().x(50f).y(100f);
- 动画学习 五
- jQuery 从零开始学习 (五) 动画
- jquery学习(五)动画
- Flex学习笔记(五) 动画效果
- cocos2d学习记录(五)-动画详解
- 绘图与动画学习笔记(五)
- Rahael学习之动画(五)
- React学习(五):动画与拖放
- cocos2d-x 菜鸟学习笔记五(精灵与动画)
- 【Dojo学习之五】强大的动画效果
- cocos2dx 3.1从零学习(五)——动画
- cocos2dx 3.1从零学习(五)——动画
- Ionic3学习笔记(五)动画之使用 animate.css
- 动画特效五:灌水动画
- Android动画学习(五)之属性动画实现Tween的效果和高级属性示例
- Cocos2d-x学习笔记(五) 精灵播放动画的两种方式
- Android Animation学习(五) ApiDemos解析:容器布局动画 LayoutTransition
- (黎活明老师讲学)Android学习(五)---Frame动画、Notification 状态栏通知
- Depends: libmpg123-0:i386 but it is not installable Recomm
- tomcat国际化
- Linux sed命令实例详解
- HDFS报错:Connection refused!
- What is AIDL?
- 动画学习 五
- 配置nginx使得主域名301重定向到www子域名
- [lintcode] - 426 Restore IP Addresses
- jQuery -- label赋值
- 亚马逊AWS的基础设施规模究竟有多大?
- 软件开发管理: 签入测试
- 技术笔记 - 初识Maven
- [Computer and Network Security] Gaining Access using Network Attacks
- Java程序员常犯的10项错误