Android動(dòng)畫(huà)之補(bǔ)間動(dòng)畫(huà)(Tween Animation)基礎(chǔ)學(xué)習(xí)
前言
之前說(shuō)過(guò)了在Android中,動(dòng)畫(huà)Animation的實(shí)現(xiàn)有兩種方式:Tween Animation(漸變動(dòng)畫(huà))和Frame Animation(幀動(dòng)畫(huà))。漸變動(dòng)畫(huà)是通過(guò)對(duì)場(chǎng)景里的對(duì)象不斷做圖像變換(平移、縮放、旋轉(zhuǎn)等)產(chǎn)生動(dòng)畫(huà)效果。幀動(dòng)畫(huà)則是通過(guò)順序播放事先準(zhǔn)備好的圖像來(lái)產(chǎn)生動(dòng)畫(huà)效果,和電影類(lèi)似。
小編也和大家分享了逐幀動(dòng)畫(huà)的基礎(chǔ)知識(shí),下面我們就來(lái)學(xué)習(xí)下Android中逐幀動(dòng)畫(huà)的基礎(chǔ)知識(shí)。
原理 : 給出開(kāi)始和結(jié)束兩個(gè)關(guān)鍵幀,兩個(gè)關(guān)鍵幀之間的插補(bǔ)幀是由計(jì)算機(jī)自動(dòng)運(yùn)算而得到的。
分類(lèi) : AlphaAnimation(透明度) ScaleAnimation(縮放) TranslateAnimation(位移) RotateAnimation (旋轉(zhuǎn)) AnimationSet(組合)
方式 :
1.在代碼中new
2.在anim文件夾下定義動(dòng)畫(huà)xml資源
效果

代碼
第一步 :準(zhǔn)備動(dòng)畫(huà)資源
目錄

<?xml version="1.0" encoding="utf-8"?> <alpha xmlns:android="http://schemas.android.com/apk/res/android" android:duration="2000" android:fromAlpha="1.0" android:interpolator="@android:anim/linear_interpolator" android:toAlpha="0.3"> </alpha>
<?xml version="1.0" encoding="utf-8"?> <rotate xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:interpolator/linear" android:repeatCount="infinite" android:repeatMode="reverse" android:duration="2000" android:fromDegrees="0" android:toDegrees="1080"> android:pivotX="50%" android:pivotY="50%" </rotate>
<?xml version="1.0" encoding="utf-8"?> <scale xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/linear_interpolator" android:duration="2000" android:fillAfter="true" android:fromXScale="1.0" android:fromYScale="1.0" android:pivotX="50%" android:pivotY="50%" android:toXScale="0.3" android:toYScale="0.3"> </scale>
<?xml version="1.0" encoding="utf-8"?> <translate xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/linear_interpolator" android:duration="2000" android:fromXDelta="10" android:fromYDelta="10" android:toXDelta="300" android:toYDelta="300"> </translate>
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/linear_interpolator" android:duration="2000"> <alpha android:fromAlpha="0.3" android:toAlpha="1.0"/> <rotate android:fromDegrees="0" android:toDegrees="360" android:pivotX="0" android:pivotY="0" android:repeatMode="restart" android:repeatCount="infinite"/> </set>
第二步 :activity_main.xml ( 略 )
第三步 :MainActivity.java
package com.lyp.anim;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity implements View.OnClickListener{
private Button btnScale;
private Button btnRotate;
private Button btnTranslate;
private Button btnAlpha;
private Button btnAll;
private ImageView mImage;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
}
private void initView() {
btnScale= (Button) findViewById(R.id.btn_scale);
btnRotate= (Button) findViewById(R.id.btn_rotate);
btnTranslate= (Button) findViewById(R.id.btn_translate);
btnAlpha= (Button) findViewById(R.id.btn_alpha);
btnAll= (Button) findViewById(R.id.btn_all);
mImage= (ImageView) findViewById(R.id.image);
btnScale.setOnClickListener(this);
btnRotate.setOnClickListener(this);
btnTranslate.setOnClickListener(this);
btnAlpha.setOnClickListener(this);
btnAll.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.btn_scale:
//加載縮放動(dòng)畫(huà)
Animation scale = AnimationUtils.loadAnimation(this, R.anim.scale);
scale.setFillAfter(true); //保留動(dòng)畫(huà)結(jié)束狀態(tài),在xml文件中設(shè)置無(wú)效!!
mImage.startAnimation(scale);
break;
case R.id.btn_rotate:
//加載旋轉(zhuǎn)動(dòng)畫(huà)
Animation rotate = AnimationUtils.loadAnimation(this, R.anim.rotate);
mImage.startAnimation(rotate);
break;
case R.id.btn_translate:
//加載位移動(dòng)畫(huà)
Animation translate = AnimationUtils.loadAnimation(this, R.anim.translate);
mImage.startAnimation(translate);
break;
case R.id.btn_alpha:
//加載透明度漸變動(dòng)畫(huà)
Animation alpha = AnimationUtils.loadAnimation(this, R.anim.alpha);
mImage.startAnimation(alpha);
break;
case R.id.btn_all:
//加載組合動(dòng)畫(huà)
Animation all = AnimationUtils.loadAnimation(this, R.anim.all);
mImage.startAnimation(all);
break;
}
}
}
總結(jié)
以上Android中補(bǔ)間動(dòng)畫(huà)(Tween Animation)基礎(chǔ)的全部?jī)?nèi)容了,動(dòng)畫(huà)Animation實(shí)現(xiàn)的兩種方式小編現(xiàn)在已經(jīng)都給大家分享了,希望能對(duì)各位Android開(kāi)發(fā)者們有所幫助,如果有疑問(wèn)大家可以留言交流。
- Android Studio實(shí)現(xiàn)補(bǔ)間動(dòng)畫(huà)
- Android動(dòng)畫(huà)系列之幀動(dòng)畫(huà)和補(bǔ)間動(dòng)畫(huà)的示例代碼
- Android動(dòng)畫(huà)學(xué)習(xí)筆記之補(bǔ)間動(dòng)畫(huà)
- Android補(bǔ)間動(dòng)畫(huà)基本使用(位移、縮放、旋轉(zhuǎn)、透明)
- Android旋轉(zhuǎn)、平移、縮放和透明度漸變的補(bǔ)間動(dòng)畫(huà)
- Android控件Tween動(dòng)畫(huà)(補(bǔ)間動(dòng)畫(huà))實(shí)現(xiàn)方法示例
- android 幀動(dòng)畫(huà),補(bǔ)間動(dòng)畫(huà),屬性動(dòng)畫(huà)的簡(jiǎn)單總結(jié)
- Android幀動(dòng)畫(huà)、補(bǔ)間動(dòng)畫(huà)、屬性動(dòng)畫(huà)用法詳解
- Android動(dòng)畫(huà)之補(bǔ)間動(dòng)畫(huà)(Tween Animation)實(shí)例詳解
- Android?Studio實(shí)現(xiàn)簡(jiǎn)單補(bǔ)間動(dòng)畫(huà)
相關(guān)文章
FrameLayout和Fragment處理Android應(yīng)用UI布局實(shí)例
這篇文章主要介紹了FrameLayout和Fragment處理Android應(yīng)用UI布局實(shí)例,安卓3.0以后Fragment的出現(xiàn)為多尺寸屏幕的適配帶來(lái)了方便,需要的朋友可以參考下2016-02-02
Android實(shí)現(xiàn)帶磁性的懸浮窗體效果
這篇文章主要介紹了Android實(shí)現(xiàn)帶磁性的懸浮窗體效果,涉及Android針對(duì)窗體的動(dòng)態(tài)操作相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2016-07-07
android MediaRecorder實(shí)現(xiàn)錄屏?xí)r帶錄音功能
這篇文章主要介紹了android MediaRecorder錄屏?xí)r帶錄音功能實(shí)現(xiàn)代碼,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-04-04
Android 自定義日期段選擇控件功能(開(kāi)始時(shí)間-結(jié)束時(shí)間)
這篇文章主要介紹了Android 自定義日期段選擇控件功能,開(kāi)始時(shí)間-結(jié)束時(shí)間。本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-04-04
Android判斷網(wǎng)絡(luò)狀態(tài)的代碼
這篇文章主要為大家詳細(xì)介紹了Android判斷網(wǎng)絡(luò)狀態(tài)的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-10-10
Android中Fragment的分屏顯示處理橫豎屏顯示的實(shí)現(xiàn)方法
今天小編就為大家分享一篇關(guān)于Android中Fragment的分屏顯示處理橫豎屏顯示的實(shí)現(xiàn)方法,小編覺(jué)得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧2019-03-03
Android實(shí)現(xiàn)京東App分類(lèi)頁(yè)面效果
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)京東App分類(lèi)頁(yè)面效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-02-02

