android:3D垂直翻转动画-FlipAnimation
- 需求
对ImageView进行相似于翻纸牌的动画 - 解决
各种Animator的组合
第一步动画:
动画代码文件1,card_flip_left_out.xml
<?
xml version="1.0" encoding="utf-8"?
>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- 先缩小 -->
<objectAnimator
android:duration="200"
android:propertyName="scaleX"
android:valueFrom="1.0"
android:valueTo="0.8" />
<objectAnimator
android:duration="200"
android:propertyName="scaleY"
android:valueFrom="1.0"
android:valueTo="0.8" />
<!-- 再旋转 -->
<objectAnimator
android:duration="@integer/card_flip_time_full"
android:interpolator="@android:interpolator/accelerate_decelerate"
android:propertyName="rotationY"
android:startOffset="200"
android:valueFrom="0"
android:valueTo="90" />
<!-- 同一时候透明度变化 -->
<objectAnimator
android:duration="@integer/card_flip_time_full"
android:propertyName="alpha"
android:startOffset="200"
android:valueFrom="1.0"
android:valueTo="0.0" />
</set>
第二步动画
动画文件2:card_flip_left_out
<?
xml version="1.0" encoding="utf-8"?
>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- 马上设置为透明 -->
<objectAnimator
android:duration="0"
android:propertyName="alpha"
android:valueFrom="1.0"
android:valueTo="0.0" />
<!-- 旋转 -->
<objectAnimator
android:duration="@integer/card_flip_time_full"
android:interpolator="@android:interpolator/accelerate_decelerate"
android:propertyName="rotationY"
android:valueFrom="-90"
android:valueTo="0" />
<!-- 旋转一半的时间。逐渐显示 -->
<objectAnimator
android:duration="1"
android:propertyName="alpha"
android:startOffset="@integer/card_flip_time_half"
android:valueFrom="0.0"
android:valueTo="1.0" />
<!-- 最后放大 -->
<objectAnimator
android:duration="200"
android:propertyName="scaleX"
android:startOffset="@integer/card_flip_time_full"
android:valueFrom="0.8"
android:valueTo="1.0" />
<objectAnimator
android:duration="200"
android:propertyName="scaleY"
android:startOffset="@integer/card_flip_time_full"
android:valueFrom="0.8"
android:valueTo="1.0" />
</set>
以下就是写java代码啦,在第一个动画结束的时候,换图。
package com.example.android.animationsdemo;
import android.animation.Animator;
import android.animation.AnimatorInflater;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
/**
* @date 2015年3月18日 下午2:28:33
* @author Zheng Haibo
* @Description: 图片的翻转动画
*/
public class ImageFlipActivity extends Activity {
private ImageView imageView;
private int clickCount = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_image_flip);
imageView = (ImageView) findViewById(R.id.iv_show);
imageView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
playFlipAnimation2();
}
});
}
private void playFlipAnimation2() {
clickCount++;
AnimatorSet animatorSetOut = (AnimatorSet) AnimatorInflater
.loadAnimator(this, R.animator.card_flip_left_out);
final AnimatorSet animatorSetIn = (AnimatorSet) AnimatorInflater
.loadAnimator(this, R.animator.card_flip_left_in);
animatorSetOut.setTarget(imageView);
animatorSetIn.setTarget(imageView);
animatorSetOut.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {// 翻转90度之后,换图
if (clickCount % 2 == 0) {
imageView.setImageResource(R.drawable.image1);
} else {
imageView.setImageResource(R.drawable.image2);
}
animatorSetIn.start();
}
});
animatorSetIn.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
// TODO
}
});
animatorSetOut.start();
}
}
- 很多其它交流
Android开发联盟QQ群:272209595
android:3D垂直翻转动画-FlipAnimation的更多相关文章
- Android立体旋转动画实现与封装(支持以X、Y、Z三个轴为轴心旋转)
本文主要介绍Android立体旋转动画,或者3D旋转,下图是我自己实现的一个界面 立体旋转分为以下三种: 1. 以X轴为轴心旋转 2. 以Y轴为轴心旋转 3. 以Z轴为轴心旋转--这种等价于andro ...
- 透过HT for Web 3D看动画Easing函数本质
http://www.hightopo.com/guide/guide/plugin/form/examples/example_easing.html 50年前的这个月诞生了BASIC这门计算机语言 ...
- Android Animation(动画)
前言 Android 平台提供实现动画的解决方案(三种) 一.3.0以前,android支持两种动画: (1)Frame Animation:顺序播放事先做好的图像,与gif图片原理类似,是一种逐帧动 ...
- 透过WebGL 3D看动画Easing函数本质
50年前的这个月诞生了BASIC这门计算机语言,回想起自己喜欢上图形界面这行,还得归功于当年在win98下用QBASIC照葫芦画瓢敲了一段绘制奥运五环的代码,当带色彩的奥运五环呈现在自己面前时我已知道 ...
- Android 三种动画详解
[工匠若水 http://blog.csdn.net/yanbober 转载请注明出处.点我开始Android技术交流] 1 背景 不能只分析源码呀,分析的同时也要整理归纳基础知识,刚好有人微博私信让 ...
- Android中的动画学习总结
android中动画可分为三种:帧动画,补间动画,和属性动画.其中属性动画是google推荐的,它可以实现前面两种动画的效果,运用起来更加灵活. 帧动画:顾名思义,就是一帧一帧的图片,快速播放形成的动 ...
- android 巧用动画使您app风骚起来
巧用Android的自定义动画,使你更加的有动感,是大多数Android开发人员的目标,那怎么做到这点.请听下文分解: 3.0以前,android支持两种动画模式,tween animation(幅间 ...
- Android中的动画使用总结
android中动画可分为三种:帧动画,补间动画,和属性动画.其中属性动画是google推荐的,它可以实现前面两种动画的效果,运用起来更加灵活. 帧动画:顾名思义,就是一帧一帧的图片,快速播放形成的动 ...
- Android中矢量动画
Android中矢量动画 Android中用<path> 标签来创建SVG,就好比控制着一支画笔,从一点到一点,动一条线. <path> 标签 支持一下属性 M = (Mx, ...
随机推荐
- 链接sql数据库并输出csv文件
__author__ = 'chunyang.wu' #作者:SelectDB # -*- coding: utf-8 -*- import MySQLdb import os os.environ[ ...
- django之创建第6-2个项目-过滤器列表
转载:http://www.lidongkui.com/django-template-filter-table 一.转化为小写 {{ name | lower }} 二.串联:先转义文本到HTML, ...
- yml转properties
推荐一个在线工具,可以将yaml转换为properties,同时也支持反向转换 http://www.toyaml.com 非常好记的地址,to yaml,直接在地址栏里输入toyaml.com,省去 ...
- Linux 系统lsblk和blkid命令
lsblk命令用于以树状的格式显示所有可用的块设备信息: [root@rhel7 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda : 10G ...
- Gerrit最简工作流
Gerrit最简工作流: git clone ... //注意clone with commit-msg hook,否则push可能失败(ERROR: missing Change-Id in c ...
- 【onethink搬家】win环境移植linux环境,注意事项
onethink 搬家注意事项: 修改目录/文件归属和权限,Runtime目录要有可写权限. 若数据库有变动,则需要更改数据库连接参数.在Application/Common/Conf/config. ...
- linux下的文本编辑器VI的使用命令
1. 移动光标 H #移到屏幕的左上角 M #移到屏幕的中间行开头 L #移到屏幕的最后一行 [ #移到文件开始位置 (双击) ] #移到文件结束位置(双击) :n #移到文件的第n行 Ctrl + ...
- Axure快速原型教程02--创建页面和设置界面
目录 Axure快速原型教程02--创建页面和设置界面 Axure快速原型教程01--原型说明下载和安装 首先,在左侧的面板中,我们发现有一个叫sitemap的面板,这个面板就是我们的一个个的页面了, ...
- ios中自定义图层
图层和VIEW的区别 1:view不具备显示功能,是因view内部有一个图层,才能显示出来 2:图层不具备事件功能,VIEW继承UIRespone具有处理事件功能 3:自定义的图层有一个影式动画,VI ...
- 国内最火的五款HTML5前端开发框架
2013-04-11 本文主要为大家推荐五款国内最火的HTML5前端开发框架,它们分别是腾讯团队开发的JX.淘宝团队开发的KISSY.百度团队开发的QWrap和Tangram,以及上海康尚实验室推出的 ...