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, ...
随机推荐
- Ubuntu18.04, WPS表格生成中文大写数字的script
=IF(ROUND(J9,2)<0,"无效数值",IF(ROUND(J9,2)=0,"零",IF(ROUND(J9,2)<1,"" ...
- 基于Pygame写的翻译方法
发布时间:2018-11-01 技术:pygame+easygui 概述 实现一个翻译功能,中英文的互相转换.并可以播放翻译后的内容. 翻译接口调用的是百度翻译的api接口. 详细 代码下载: ...
- 移动端强大的富文本编辑器richeditor-android
代码地址如下:http://www.demodashi.com/demo/14883.html 一.运行效果图 二.代码具体实现 1.引入richeditor-android richeditor-a ...
- 【php+uploadify3.2】上传按钮点击一点反应都没有,原因
原因: 代码没有问题,这个原因也困扰我一段时间,是由于浏览器禁用了flash,需要放开,操作方法如下: 在谷歌浏览器输入:chrome://settings/content/flash 然后添加需要该 ...
- 关于js中的回调函数callback
来源于:http://www.jianshu.com/p/6bc353e5f7a3 前言 其实我一直很困惑关于js 中的callback,困惑的原因是,学习中这块看的资料少,但是平时又经常见,偶尔复制 ...
- Debug 路漫漫-06
FSBPR 迭代一轮就停止???…… 循环条件没有问题.. 达到收敛条件了?——参数变化小于1e-4…? deltaU =0 —— U没有更新?——incU < 0 —— 取消动量(前半部分即可 ...
- iOS应用间相互跳转
使用第三方用户登录,跳转到需授权的App.如QQ登录,微信登录等. 需要用户授权,还需要"返回到调用的程序,同时返回授权的用户名.密码". 应用程序推广,跳转到另一个应用程序(本机 ...
- 【DeepLearning】Exercise:Softmax Regression
Exercise:Softmax Regression 习题的链接:Exercise:Softmax Regression softmaxCost.m function [cost, grad] = ...
- lsof命令详解(转)
lsof命令详解(转) 上一篇 / 下一篇 2011-06-09 21:56:41 / 个人分类:Linux 查看( 351 ) / 评论( 0 ) / 评分( 0 / 0 ) 在Linux中,ls ...
- nginx init 官方启动脚本
#!/bin/sh # # nginx - this script starts and stops the nginx daemon # # chkconfig: - 85 15 # descrip ...