欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

android 幀動(dòng)畫,補(bǔ)間動(dòng)畫,屬性動(dòng)畫的簡(jiǎn)單總結(jié)

 更新時(shí)間:2017年01月05日 16:13:49   作者:S丶black  
本文主要對(duì)android 幀動(dòng)畫,補(bǔ)間動(dòng)畫,屬性動(dòng)畫進(jìn)行了簡(jiǎn)單總結(jié),具有一定的參考價(jià)值,下面跟著小編一起來(lái)看下吧

幀動(dòng)畫——FrameAnimation

將一系列圖片有序播放,形成動(dòng)畫的效果。其本質(zhì)是一個(gè)Drawable,是一系列圖片的集合,本身可以當(dāng)做一個(gè)圖片一樣使用

在Drawable文件夾下,創(chuàng)建animation-list為根節(jié)點(diǎn)的資源文件

<animation-list android:oneshot="false">
 <item android:drawable="@drawable/img1" android:duration="100"/>
 <item android:drawable="@drawable/img2" android:duration="100"/>
 <item android:drawable="@drawable/img3" android:duration="100"/>
 <item android:drawable="@drawable/img4" android:duration="100"/>
</animation-list>

oneshot:是否只播放一次     

drawable:一幀引用的圖片

duration:一幀播放的時(shí)間

播放動(dòng)畫

將動(dòng)畫作為控件的背景

((AnimationDrawable)view.getBackground()).start();

Animation常用屬性

duration:動(dòng)畫時(shí)間                  

repeatCount:重復(fù)次數(shù) infinite無(wú)限次

fillAfter:是否停止在最后一幀

repeatMode:重復(fù)模式     值:restart重新開(kāi)始,reserve反復(fù)

startOffset:開(kāi)始延遲時(shí)間

補(bǔ)間動(dòng)畫 Tween Animation

只能應(yīng)用于View對(duì)象,只支持部分屬性,View animation值改變了View繪制的位置,并沒(méi)有改變對(duì)象本身的真實(shí)位置

可以使用XML定義也可以使用代碼定義     XML定義的動(dòng)畫放在/res/anim/文件夾內(nèi)

開(kāi)始動(dòng)畫 通過(guò)view的startAnimation(Animation a)  參數(shù)定義的動(dòng)畫

四種補(bǔ)間動(dòng)畫通過(guò)XML定義

AlphaAnimation:透明度動(dòng)畫

<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
 android:fromAlpha="0"
 android:toAlpha="1"
 android:duration="2000">
 <!--
 fromAlpha 起始透明度 0為完全透明 1為不透明 0~1之間的浮點(diǎn)值
 toAlpha 結(jié)束透明度
 duration 動(dòng)畫運(yùn)行時(shí)間 單位毫秒
 -->
</alpha>
AlphaAnimation alphaAnimation=null;
 //加載XML中的動(dòng)畫XML文件
 alphaAnimation= (AlphaAnimation) AnimationUtils.loadAnimation(MainActivity.this, R.anim.anim_alpha);
 //常用屬性設(shè)置 各種動(dòng)畫通用
 alphaAnimation.setRepeatCount(3);//執(zhí)行動(dòng)畫效果結(jié)束后重復(fù)執(zhí)行3次 一共4次
 alphaAnimation.setRepeatMode(Animation.REVERSE);//重復(fù)模式
 //動(dòng)畫結(jié)束是否停止在最后一幀
 alphaAnimation.setFillAfter(true);
 //動(dòng)畫結(jié)束是否停止在第一幀
 alphaAnimation.setFillBefore(false);
 //設(shè)置插值器 動(dòng)畫執(zhí)行速度 變速 加減速。。
 //AccelerateInterpolator減速
 //DecelerateInterpolator加速
 alphaAnimation.setInterpolator(new AccelerateDecelerateInterpolator());

ScaleAnimation:縮放動(dòng)畫

代碼加載的方式和方法的使用與AlphaAnimation一樣

<?xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
 android:toXScale="1"
 android:toYScale="1"
 android:fromXScale="0.1"
 android:fromYScale="0.1"
 android:pivotY="0%"
 android:pivotX="0%"
 android:duration="2000">
 <!--
  浮點(diǎn)值 表示倍數(shù) 自身幾倍
  fromXScale 動(dòng)畫在X軸以自身幾倍伸縮開(kāi)始
  toXScale 動(dòng)畫在X軸以自身幾倍伸縮結(jié)束
  fromYScale 動(dòng)畫在Y軸以自身幾倍伸縮開(kāi)始
  toYScale 動(dòng)畫在Y軸以自身幾倍伸縮結(jié)束
  pivotX 動(dòng)畫相對(duì)于控件自身的X坐標(biāo)的開(kāi)始位置
  pivotY 動(dòng)畫相對(duì)于控件自身的Y坐標(biāo)的開(kāi)始位置
  0% 0% 表示控件左上角 為0,0原點(diǎn)坐標(biāo)
 -->
</scale>

TranslateAnimation:平移動(dòng)畫

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
 android:fromXDelta="-100%p"
 android:fromYDelta="0"
 android:toXDelta="100%p"
 android:toYDelta="0"
 android:duration="2000">
 <!--
  fromXDelta x軸起始位置
  toXDelta X軸結(jié)束位置
  fromYDelta y軸起始位置
  toYDelta y軸結(jié)束位置
  100%p 表示相對(duì)于父級(jí)
  100%相對(duì)于自身
-->
</translate>

RotateAnimation:旋轉(zhuǎn)動(dòng)畫

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
 android:fromDegrees="0"
 android:toDegrees="360"
 android:duration="2000"
 android:pivotX="50%"
 android:pivotY="50%"
android:interpolator="@android:anim/accelerate_decelerate_interpolator">
 <!--
 interpolator 指定動(dòng)畫的插值器
 accelerate_decelerate_interpolator 加速-減速
 accelerate_interpolator  加速
 decelerate_interpolator  減速
 fromDegrees 動(dòng)畫起始角度
 toDegrees 動(dòng)畫結(jié)束旋轉(zhuǎn)的角度 可以大于360度
 負(fù)數(shù)表示逆時(shí)針旋轉(zhuǎn) 正數(shù)表示順時(shí)針旋轉(zhuǎn)
 pivotX相對(duì)于view的X坐標(biāo)的開(kāi)始位置
 pivotY相對(duì)于view的Y坐標(biāo)的開(kāi)始位置
絕對(duì)尺寸 100px
 50% 相對(duì)尺寸 相對(duì)于自身的50%
 50%p 相對(duì)尺寸 相對(duì)于父容器的50%
 50%為物件的X或Y方向坐標(biāo)上的中點(diǎn)位置
 duration 動(dòng)畫播放時(shí)間 單位毫秒
-->
</rotate>

通過(guò)構(gòu)造方法創(chuàng)建 

構(gòu)造參數(shù)詳解  此段內(nèi)容選自 http://www.cnblogs.com/aimeng/archive/2011/10/10/2206710.html 

//在代碼中定義 動(dòng)畫實(shí)例對(duì)象
private Animation myAnimation_Alpha;
private Animation myAnimation_Scale;
private Animation myAnimation_Translate;
private Animation myAnimation_Rotate;
 
 //根據(jù)各自的構(gòu)造方法來(lái)初始化一個(gè)實(shí)例對(duì)象
myAnimation_Alpha=new AlphaAnimation(0.1f, 1.0f);
 
myAnimation_Scale =new ScaleAnimation(0.0f, 1.4f, 0.0f, 1.4f,
  Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
 
myAnimation_Translate=new TranslateAnimation(30.0f, -80.0f, 30.0f, 300.0f);
 
myAnimation_Rotate=new RotateAnimation(0.0f, +350.0f,
  Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF, 0.5f);

AlphaAnimation

AnimationAlphaAnimation(float fromAlpha, float toAlpha)
//第一個(gè)參數(shù)fromAlpha為 動(dòng)畫開(kāi)始時(shí)候透明度
//第二個(gè)參數(shù)toAlpha為 動(dòng)畫結(jié)束時(shí)候透明度
myAnimation_Alpha=new AlphaAnimation(0.1f, 1.0f);
//說(shuō)明:
//  0.0表示完全透明
//  1.0表示完全不透明
myAnimation_Alpha.setDuration(5000);
//設(shè)置時(shí)間持續(xù)時(shí)間為 5000毫秒

ScaleAnimation

ScaleAnimation(float fromX, float toX, float fromY, float toY,
   int pivotXType, float pivotXValue, int pivotYType, float pivotYValue) 
 //第一個(gè)參數(shù)fromX為動(dòng)畫起始時(shí) X坐標(biāo)上的伸縮尺寸 
 //第二個(gè)參數(shù)toX為動(dòng)畫結(jié)束時(shí) X坐標(biāo)上的伸縮尺寸 
 //第三個(gè)參數(shù)fromY為動(dòng)畫起始時(shí)Y坐標(biāo)上的伸縮尺寸 
 //第四個(gè)參數(shù)toY為動(dòng)畫結(jié)束時(shí)Y坐標(biāo)上的伸縮尺寸 
 /*說(shuō)明:
    以上四種屬性值 
    0.0表示收縮到?jīng)]有 
    1.0表示正常無(wú)伸縮 
    值小于1.0表示收縮 
    值大于1.0表示放大
 */
 //第五個(gè)參數(shù)pivotXType為動(dòng)畫在X軸相對(duì)于物件位置類型 
 //第六個(gè)參數(shù)pivotXValue為動(dòng)畫相對(duì)于物件的X坐標(biāo)的開(kāi)始位置
 //第七個(gè)參數(shù)pivotXType為動(dòng)畫在Y軸相對(duì)于物件位置類型 
 //第八個(gè)參數(shù)pivotYValue為動(dòng)畫相對(duì)于物件的Y坐標(biāo)的開(kāi)始位置
 myAnimation_Scale =new ScaleAnimation(0.0f, 1.4f, 0.0f, 1.4f,
   Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
 myAnimation_Scale.setDuration(700);
 //設(shè)置時(shí)間持續(xù)時(shí)間為 700毫秒

TranslateAnimation

TranslateAnimation(float fromXDelta, float toXDelta,
    float fromYDelta, float toYDelta) 
 //第一個(gè)參數(shù)fromXDelta為動(dòng)畫起始時(shí) X坐標(biāo)上的移動(dòng)位置 
 //第二個(gè)參數(shù)toXDelta為動(dòng)畫結(jié)束時(shí) X坐標(biāo)上的移動(dòng)位置 
 //第三個(gè)參數(shù)fromYDelta為動(dòng)畫起始時(shí)Y坐標(biāo)上的移動(dòng)位置 
 //第四個(gè)參數(shù)toYDelta為動(dòng)畫結(jié)束時(shí)Y坐標(biāo)上的移動(dòng)位置 

RotateAnimation

RotateAnimation(float fromDegrees, float toDegrees, 
   int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)
 //第一個(gè)參數(shù)fromDegrees為動(dòng)畫起始時(shí)的旋轉(zhuǎn)角度 
 //第二個(gè)參數(shù)toDegrees為動(dòng)畫旋轉(zhuǎn)到的角度 
 //第三個(gè)參數(shù)pivotXType為動(dòng)畫在X軸相對(duì)于物件位置類型 
 //第四個(gè)參數(shù)pivotXValue為動(dòng)畫相對(duì)于物件的X坐標(biāo)的開(kāi)始位置
 //第五個(gè)參數(shù)pivotXType為動(dòng)畫在Y軸相對(duì)于物件位置類型 
 //第六個(gè)參數(shù)pivotYValue為動(dòng)畫相對(duì)于物件的Y坐標(biāo)的開(kāi)始位置
 myAnimation_Rotate=new RotateAnimation(0.0f, +350.0f, Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF, 0.5f);

屬性動(dòng)畫

相對(duì)補(bǔ)間動(dòng)畫  屬性動(dòng)畫會(huì)真正的使目標(biāo)對(duì)象的屬性值發(fā)生改變,不像補(bǔ)間動(dòng)畫只是影像的改變    只能修改具有g(shù)et/set方法的屬性值

因?yàn)榭梢孕薷膶?duì)象的屬性,屬性動(dòng)畫可以做到更多的效果,改變文本大小,背景顏色等等

屬性動(dòng)畫創(chuàng)建在 res/animator

ValueAnimator

包含屬性動(dòng)畫的所有核心功能,動(dòng)畫時(shí)間,開(kāi)始、結(jié)束屬性值,屬性值計(jì)算方法等。

ValuAnimiator設(shè)置開(kāi)始結(jié)束值 實(shí)現(xiàn)ValueAnimator.onUpdateListener接口,

這個(gè)接口只有一個(gè)函數(shù)onAnimationUpdate(),在這個(gè)函數(shù)中會(huì)傳入ValueAnimator對(duì)象做為參數(shù),通過(guò)這個(gè)ValueAnimator對(duì)象的getAnimatedValue()函數(shù)可以得到當(dāng)前的屬性值

把屬性值設(shè)置給某個(gè)控件的某個(gè)屬性

使用xml

<?xml version="1.0" encoding="utf-8"?>
<animator xmlns:android="http://schemas.android.com/apk/res/android"
 android:duration="1000"
 android:valueFrom="0"
 android:valueTo="300"
 android:valueType="intType"
android:interpolator="@android:interpolator/overshoot">
 <!--
 valueFrom 起始值
 valueTo 結(jié)束值
 valueType 值的類型
 intType整數(shù)值、floatType浮點(diǎn)值、colorType顏色值
 interpolator插值器
 -->
</animator>
ValueAnimator valueAnimator=null;
 //通過(guò)AnimatorInflater.loadAnimator()加載xml 創(chuàng)建ValueAnimator
 valueAnimator= (ValueAnimator) AnimatorInflater.loadAnimator(this,R.animator.animator_value);
 //動(dòng)畫執(zhí)行時(shí)間
 valueAnimator.setDuration(3000);
 //值改變監(jiān)聽(tīng)
 valueAnimator.addUpdateListener(listener);
 //開(kāi)始動(dòng)畫
 valueAnimator.start();
private ValueAnimator.AnimatorUpdateListener listener=new ValueAnimator.AnimatorUpdateListener() {
 @Override
 public void onAnimationUpdate(ValueAnimator animation) {
       //獲取值
  int value= (int) animation.getAnimatedValue();
       //btnValueAnimator為測(cè)試控件
        //設(shè)置控件X軸平移
        btnValueAnimator.setTranslationX(value);
 }
 };

使用代碼

/**
  * valueAnimator 單個(gè)值
  */
 //代碼創(chuàng)建 ValueAnimator類自身的方法
 //ofFloat值類型float
 ValueAnimator valueAnimator=ValueAnimator.ofFloat(0,1);
 //ofInt值類型int 從0~300
 valueAnimator=ValueAnimator.ofInt(0,300);
 //也可以用來(lái)設(shè)置顏色 在顏色改變過(guò)程中會(huì)將顏色變化情況顯示出來(lái)
 //紅色到藍(lán)色的改變過(guò)程 顯示N種顏色
 valueAnimator=ValueAnimator.ofInt(Color.RED,Color.BLUE);
 //ofArgb設(shè)置顏色 如果無(wú)法使用 是的sdk版本低了
 //這個(gè)方法改變顏色過(guò)程中只顯示紅色和藍(lán)色
 //valueAnimator=ValueAnimator.ofArgb(Color.RED,Color.BLUE);
 //設(shè)置插值器
 valueAnimator.setInterpolator(new CycleInterpolator());
 /**
  *
  * ValueAnimator.ofPropertyValuesHolder 設(shè)置多個(gè)值
  */
 //設(shè)置動(dòng)畫屬性 參數(shù)1:名字 參數(shù)2,3值的變化區(qū)間
 PropertyValuesHolder alphaHolder=PropertyValuesHolder.ofFloat("alpha",0f,1f);
 PropertyValuesHolder widthHolder=PropertyValuesHolder.ofInt("width",0,300);
 //ValueAnimator.ofPropertyValuesHolder 添加holder 創(chuàng)建動(dòng)畫
valueAnimator=ValueAnimator.ofPropertyValuesHolder(alphaHolder,widthHolder);
 //動(dòng)畫執(zhí)行時(shí)間
 valueAnimator.setDuration(3000);
 //值改變監(jiān)聽(tīng)
 valueAnimator.addUpdateListener(listener);
private ValueAnimator.AnimatorUpdateListener listener=new ValueAnimator.AnimatorUpdateListener() {
 @Override
 public void onAnimationUpdate(ValueAnimator animation) {
  /**
  * 單個(gè)值獲取 getAnimatedValue取出變化值 根據(jù)設(shè)置類型強(qiáng)轉(zhuǎn)
  * btnValueAnimator 測(cè)試用的button
  */
//  int value= (int) animation.getAnimatedValue();
//  btnValueAnimator.setTranslationX(value);橫坐標(biāo)平移
//  float value= (float) valueAnimator.getAnimatedValue();
//  btnValueAnimator.setAlpha(value);透明度改變
//  int value= (int) animation.getAnimatedValue();
//  btnValueAnimator.setTextColor(value);文字顏色改變
  /**
  * PropertyValuesHolder存了多個(gè)值 通過(guò)名字獲取 強(qiáng)制轉(zhuǎn)換
  */
  float alpha= (float) valueAnimator.getAnimatedValue("alpha");
  int width= (int) valueAnimator.getAnimatedValue("width");
  btnValueAnimator.setAlpha(alpha);//改變透明度
  //圖像繪制 左邊不變從右邊慢慢增加
  //修改控件的width height不能使用setWidth或setHeight
  btnValueAnimator.setRight(width);
  //btnValueAnimator.setBottom(width);

 }
 };

ObjectAnimator:

繼承自ValueAnimator,要指定一個(gè)對(duì)象及該對(duì)象的一個(gè)屬性,當(dāng)屬性值計(jì)算完成時(shí)自動(dòng)設(shè)置為該對(duì)象的相應(yīng)屬性,不需要設(shè)置監(jiān)聽(tīng),底層自動(dòng)完成,一般會(huì)用ObjectAnimator來(lái)改變某一對(duì)象的某一屬性

//用來(lái)測(cè)試的button
 Button btnObjectAnimator= (Button) findViewById(R.id.btn_object_animator);
 //加載動(dòng)畫
 ObjectAnimator objectAnimator= (ObjectAnimator) AnimatorInflater.loadAnimator(this,R.animator.animator_object);
 //綁定控件
 objectAnimator.setTarget(btnObjectAnimator);
 //參數(shù)1 綁定控件 參數(shù)2 設(shè)置 屬性 參數(shù)3 設(shè)置值
 objectAnimator=ObjectAnimator.ofInt(btnObjectAnimator,"textColor",Color.RED);
 //PropertyValuesHolder設(shè)置多個(gè)屬性
 PropertyValuesHolder translationXHolder=PropertyValuesHolder.ofFloat("translationX",0,300);
 PropertyValuesHolder translationYHolder=PropertyValuesHolder.ofFloat("translationY",0,200);
objectAnimator=ObjectAnimator.ofPropertyValuesHolder(btnObjectAnimator,translationXHolder,translationYHolder);
 objectAnimator.setDuration(3000);
     //開(kāi)始動(dòng)畫
     objectAnimator.start();

以上就是本文的全部?jī)?nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,同時(shí)也希望多多支持腳本之家!

相關(guān)文章

最新評(píng)論