android使用FlipAnimation實(shí)現(xiàn)3D垂直翻轉(zhuǎn)動(dòng)畫(huà)
本文實(shí)例為大家分享了android實(shí)現(xiàn)3D垂直翻轉(zhuǎn)動(dòng)畫(huà)的具體代碼,供大家參考,具體內(nèi)容如下
需求
對(duì)ImageView進(jìn)行類(lèi)似于翻紙牌的動(dòng)畫(huà)
解決
各種Animator的組合
第一步動(dòng)畫(huà):
動(dòng)畫(huà)代碼文件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)畫(huà)
動(dòng)畫(huà)文件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>
下面就是寫(xiě)java代碼啦,在第一個(gè)動(dòng)畫(huà)結(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)畫(huà)
*/
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();
}
}
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android實(shí)現(xiàn)圖片反轉(zhuǎn)、翻轉(zhuǎn)、旋轉(zhuǎn)、放大和縮小
- Android動(dòng)畫(huà)之3D翻轉(zhuǎn)效果實(shí)現(xiàn)函數(shù)分析
- Android圖片翻轉(zhuǎn)動(dòng)畫(huà)簡(jiǎn)易實(shí)現(xiàn)代碼
- Android實(shí)現(xiàn)Flip翻轉(zhuǎn)動(dòng)畫(huà)效果
- Android實(shí)現(xiàn)文字翻轉(zhuǎn)動(dòng)畫(huà)的效果
- Android實(shí)現(xiàn)3D翻轉(zhuǎn)動(dòng)畫(huà)效果
- Android利用Camera實(shí)現(xiàn)中軸3D卡牌翻轉(zhuǎn)效果
- Android實(shí)現(xiàn)卡片翻轉(zhuǎn)動(dòng)畫(huà)
- android camera yuv幀水平翻轉(zhuǎn)實(shí)例
- android實(shí)現(xiàn)撲克卡片翻轉(zhuǎn)
相關(guān)文章
快速解決fragment中onActivityResult不調(diào)用的問(wèn)題
下面小編就為大家?guī)?lái)一篇快速解決fragment中onActivityResult不調(diào)用的問(wèn)題。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-04-04
直接應(yīng)用項(xiàng)目中的Android圖片緩存技術(shù)
這篇文章主要為大家詳細(xì)介紹了直接應(yīng)用項(xiàng)目中的Android圖片緩存技術(shù),簡(jiǎn)單、方便、高效,感興趣的小伙伴們可以參考一下2016-04-04
Android應(yīng)用中實(shí)現(xiàn)選擇本地文件與目錄的實(shí)例分享
這篇文章主要介紹了Android應(yīng)用中實(shí)現(xiàn)選擇本地文件與目錄的實(shí)例分享,相當(dāng)于從app內(nèi)呼出的簡(jiǎn)易的資源管理器來(lái)使用本地資源,需要的朋友可以參考下2016-02-02
關(guān)于Android短信驗(yàn)證碼的獲取的示例
本篇文章主要介紹了關(guān)于Android短信驗(yàn)證碼的獲取的示例,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-08-08
Android開(kāi)發(fā)壁紙的驗(yàn)證設(shè)置和確認(rèn)功能實(shí)現(xiàn)demo
android?wallpaper包括鎖屏壁紙和桌面壁紙,壁紙又區(qū)分靜態(tài)和動(dòng)態(tài)兩種。本文詳細(xì)介紹靜態(tài)壁紙?jiān)O(shè)置和確認(rèn),有需要的朋友可以借鑒參考下,希望能夠有所幫助2022-04-04
Android抓取CSDN首頁(yè)極客頭條內(nèi)容完整實(shí)例
這篇文章主要介紹了Android抓取CSDN首頁(yè)極客頭條內(nèi)容完整實(shí)例,具有一定借鑒價(jià)值,需要的朋友可以參考下2018-01-01

