android使用FlipAnimation實(shí)現(xiàn)3D垂直翻轉(zhuǎn)動(dòng)畫
本文實(shí)例為大家分享了android實(shí)現(xiàn)3D垂直翻轉(zhuǎn)動(dòng)畫的具體代碼,供大家參考,具體內(nèi)容如下
需求
對ImageView進(jìn)行類似于翻紙牌的動(dòng)畫
解決
各種Animator的組合
第一步動(dòng)畫:
動(dòng)畫代碼文件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" /> <!-- 再旋轉(zhuǎn) --> <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" /> <!-- 同時(shí)透明度變化 --> <objectAnimator android:duration="@integer/card_flip_time_full" android:propertyName="alpha" android:startOffset="200" android:valueFrom="1.0" android:valueTo="0.0" /> </set>
第二步動(dòng)畫
動(dòng)畫文件2:card_flip_left_out
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" > <!-- 立即設(shè)置為透明 --> <objectAnimator android:duration="0" android:propertyName="alpha" android:valueFrom="1.0" android:valueTo="0.0" /> <!-- 旋轉(zhuǎn) --> <objectAnimator android:duration="@integer/card_flip_time_full" android:interpolator="@android:interpolator/accelerate_decelerate" android:propertyName="rotationY" android:valueFrom="-90" android:valueTo="0" /> <!-- 旋轉(zhuǎn)一半的時(shí)間,逐漸顯示 --> <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代碼啦,在第一個(gè)動(dòng)畫結(jié)束的時(shí)候,換圖。
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: 圖片的翻轉(zhuǎn)動(dòng)畫
*/
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) {// 翻轉(zhuǎn)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();
}
}
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android實(shí)現(xiàn)圖片反轉(zhuǎn)、翻轉(zhuǎn)、旋轉(zhuǎn)、放大和縮小
- Android動(dòng)畫之3D翻轉(zhuǎn)效果實(shí)現(xiàn)函數(shù)分析
- Android圖片翻轉(zhuǎn)動(dòng)畫簡易實(shí)現(xiàn)代碼
- Android實(shí)現(xiàn)Flip翻轉(zhuǎn)動(dòng)畫效果
- Android實(shí)現(xiàn)文字翻轉(zhuǎn)動(dòng)畫的效果
- Android實(shí)現(xiàn)3D翻轉(zhuǎn)動(dòng)畫效果
- Android利用Camera實(shí)現(xiàn)中軸3D卡牌翻轉(zhuǎn)效果
- Android實(shí)現(xiàn)卡片翻轉(zhuǎn)動(dòng)畫
- android camera yuv幀水平翻轉(zhuǎn)實(shí)例
- android實(shí)現(xiàn)撲克卡片翻轉(zhuǎn)
相關(guān)文章
Android簡單實(shí)現(xiàn)計(jì)算器功能
這篇文章主要為大家詳細(xì)介紹了Android簡單實(shí)現(xiàn)計(jì)算器功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-08-08
詳解Android的網(wǎng)絡(luò)數(shù)據(jù)存儲(chǔ)
LeanCloud是一種簡單高效的數(shù)據(jù)和文件存儲(chǔ)服務(wù),本文主要介紹了利用LeanCloud來進(jìn)行網(wǎng)絡(luò)數(shù)據(jù)的存儲(chǔ)的實(shí)現(xiàn)方法。具有很好的參考價(jià)值,需要的朋友一起來看下吧2016-12-12
sqlite查詢結(jié)果在listview中展示的實(shí)現(xiàn)
下面小編就為大家?guī)硪黄猻qlite查詢結(jié)果在listview中展示的實(shí)現(xiàn)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-04-04
Android工具欄頂出轉(zhuǎn)場動(dòng)畫的實(shí)現(xiàn)方法實(shí)例
這篇文章主要給大家介紹了關(guān)于Android工具欄頂出轉(zhuǎn)場動(dòng)畫的實(shí)現(xiàn)方法,文中通過示例代碼介紹的非常詳細(xì),對各位Android開發(fā)者們具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2018-09-09
Android輔助功能實(shí)現(xiàn)自動(dòng)搶紅包(附源碼)
本篇文章主要介紹了Android輔助功能實(shí)現(xiàn)自動(dòng)搶紅包(附源碼),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-11-11

