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

Android實(shí)現(xiàn)動(dòng)畫效果詳解

 更新時(shí)間:2015年07月24日 15:29:11   作者:掌緣生滅  
這篇文章主要介紹了Android實(shí)現(xiàn)動(dòng)畫效果詳解,目前Android平臺(tái)提供了Tween動(dòng)畫和Frame動(dòng)畫,實(shí)現(xiàn)這兩類動(dòng)畫有兩種方式:一種使用XML文件(文件放在res/anim),一種直接代碼搞定,需要的朋友可以參考下

目前Android平臺(tái)提供了兩類動(dòng)畫一類是Tween動(dòng)畫,第二類就是 Frame動(dòng)畫,具體內(nèi)容介紹請(qǐng)看下文:

一類是Tween動(dòng)畫,就是對(duì)場(chǎng)景里的對(duì)象不斷的進(jìn)行圖像變化來產(chǎn)生動(dòng)畫效果(旋轉(zhuǎn)、平移、放縮和漸變)。

第二類就是 Frame動(dòng)畫,即順序的播放事先做好的圖像,與gif圖片原理類似。

實(shí)現(xiàn)動(dòng)畫有兩種方式:一種使用XML文件(文件放在res/anim),一種直接代碼搞定

 1、透明度控制動(dòng)畫效果alpha

<!--
透明度控制動(dòng)畫效果alpha
 浮點(diǎn)型值:
 fromAlpha 動(dòng)畫起始時(shí)透明度
 toAlpha 動(dòng)畫結(jié)束時(shí)透明度
 說明:0.0 完全透明
 1.0 完全不透明
 以上值取0.0-1.0之間的 float數(shù)據(jù)類型的數(shù)字
duration 為動(dòng)畫持續(xù)時(shí)間
長(zhǎng)整型:
說明:時(shí)間以毫秒為單位
-->
<alpha
 android:duration="3000"
 android:fromAlpha="0.0"
 android:toAlpha="1.0" />

代碼方式:

復(fù)制代碼 代碼如下:

Animation animationAlpha = new AlphaAnimation(0.0f, 1.0f);
animationAlpha.setDuration(3000);
ivAnim.startAnimation(animationAlpha);
 

2、rotate旋轉(zhuǎn)動(dòng)畫

<!--
rotate旋轉(zhuǎn)動(dòng)畫效果

屬性:interpolator 指定一個(gè)動(dòng)畫的插入器
有三種動(dòng)畫插入器:
 accelerate_decelerate_interpolator 加速-減速 動(dòng)畫插入器
 accelerate_interpolator 加速-動(dòng)畫插入器
 decelerate_interpolator 減速-動(dòng)畫插入器
 其他的屬于特定的動(dòng)畫效果

浮點(diǎn)整型值:
 fromDegrees 為動(dòng)畫起始時(shí)物件的角度
 toDegrees 為動(dòng)畫起始時(shí)物件旋轉(zhuǎn)的角度 可以大于360度
說明:當(dāng)角度為負(fù)數(shù)——表示逆時(shí)針旋轉(zhuǎn)
  當(dāng)角度為正數(shù)——表示順時(shí)針旋轉(zhuǎn)
  (負(fù)數(shù)from——to正數(shù):順時(shí)針旋轉(zhuǎn)
  負(fù)數(shù)from——to負(fù)數(shù):逆時(shí)針旋轉(zhuǎn)
  正數(shù)from——to正數(shù):順時(shí)針旋轉(zhuǎn))
  
pivotX 為動(dòng)畫相對(duì)于物件的X坐標(biāo)的開始位置
pivotY 為動(dòng)畫相對(duì)于物件的Y坐標(biāo)的開始位置
說明:以上兩個(gè)屬性值 從0%——100%中取值
 50%為物件的X或Y方向坐標(biāo)上的中點(diǎn)位置
長(zhǎng)整型類型:
duration 為動(dòng)畫持續(xù)時(shí)間
說明:時(shí)間以毫秒為單位
 -->
<rotate
 android:duration="3000"
 android:fromDegrees="0"
 android:interpolator="@android:anim/accelerate_decelerate_interpolator"
 android:pivotX="50%"
 android:pivotY="50%"
 android:toDegrees="+350" />

復(fù)制代碼 代碼如下:

Animation animationRotate = new RotateAnimation(0.0f, +350.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
animationRotate.setDuration(3000);
ivAnim.startAnimation(animationRotate);

3、尺寸伸縮動(dòng)畫效果 scale

<!--
尺寸伸縮動(dòng)畫效果 scale
屬性:interpolator 指定一個(gè)動(dòng)畫的插入器
  有三種動(dòng)畫插入器:
  accelerate_decelerate_interpolator 加速-減速 動(dòng)畫插入器
  accelerate_interpolator 加速-動(dòng)畫插入器
  decelerate_interpolator 減速-動(dòng)畫插入器
  其他的屬于特定的動(dòng)畫效果
浮點(diǎn)型值:
 fromXScale 動(dòng)畫起始時(shí) X坐標(biāo)上的伸縮尺寸
 toXScale 動(dòng)畫結(jié)束時(shí) X坐標(biāo)上的伸縮尺寸
 fromYScale 動(dòng)畫起始 Y時(shí)坐標(biāo)上的伸縮尺寸
 toYScale 動(dòng)畫結(jié)束時(shí) Y坐標(biāo)上的尺寸
 說明:以上四種屬性值
 0.0表示收縮到?jīng)]有
 1.0表示正常無伸縮
  值小于1.0表示收縮
  值大于1.0表示放大
 pivotX 動(dòng)畫相對(duì)于物件的X坐標(biāo)的開始位置
 pivotY 動(dòng)畫相對(duì)于武將的Y坐標(biāo)的開始位置
 說明:以上兩個(gè)屬性值 從0%-100%中取值
 長(zhǎng)整型:
 duration 動(dòng)畫持續(xù)時(shí)間
 說明:時(shí)間以毫秒為單位
 布爾型值:
 fillAfter 當(dāng)設(shè)置為true,該動(dòng)畫轉(zhuǎn)化在動(dòng)畫結(jié)束后被應(yīng)用
-->

<scale
 android:duration="700"
 android:fillAfter="false"
 android:fromXScale="0.0"
 android:fromYScale="0.0"
 android:interpolator="@android:anim/accelerate_decelerate_interpolator"
 android:pivotX="50%"
 android:pivotY="50%"
 android:toXScale="1.4"
 android:toYScale="1.4" />

代碼方式:

Animation animationScale = new ScaleAnimation(0.0f, 1.4f, 0.0f, 1.4f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
animationScale.setDuration(3000);
ivAnim.startAnimation(animationScale);

4、translate 位置轉(zhuǎn)移動(dòng)畫效果

<!--
translate 位置轉(zhuǎn)移動(dòng)畫效果
 整型值:
 fromXDelta 動(dòng)畫起始時(shí) X坐標(biāo)上的位置 
 toXDelta 動(dòng)畫結(jié)束時(shí) X坐標(biāo)上的位置
 fromYDelta 動(dòng)畫起始時(shí) Y坐標(biāo)上的位置
 toYDlta 動(dòng)畫結(jié)束時(shí) Y坐標(biāo)上的位置
 注意:沒有指定fromXTra toXType fromYType toYType 時(shí)候,默認(rèn)是以自己為相對(duì)參照物
 長(zhǎng)整型:duration 為動(dòng)畫持續(xù)時(shí)間
    時(shí)間以毫秒為單位
-->

<translate
 android:duration="2000"
 android:fromXDelta="30"
 android:fromYDelta="30"
 android:toXDelta="-80"
 android:toYDelta="300" />

復(fù)制代碼 代碼如下:

Animation animationTranslate = new TranslateAnimation(30.0f, -80.0f, 30.0f, 300.0f);
animationTranslate.setDuration(3000);
ivAnim.startAnimation(animationTranslate);
 

xml文件方式使用的話就兩行代碼

復(fù)制代碼 代碼如下:

Animation anim = AnimationUtils.loadAnimation(activity, R.anim.anim_xxx);
ivAnim.startAnimation(anim);
 

5、frame幀動(dòng)畫(文件放在res/drawable)

<!--
 根標(biāo)簽為animation-list,其中oneshot代表著是否只展示一遍,設(shè)置為false會(huì)不停的循環(huán)播放動(dòng)畫 
 根標(biāo)簽下,通過item標(biāo)簽對(duì)動(dòng)畫中的每一個(gè)圖片進(jìn)行聲明 
 android:duration 表示展示所用的該圖片的時(shí)間長(zhǎng)度 

-->
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
 android:oneshot="true" >

 <item
 android:drawable="@drawable/icon_frame1"
 android:duration="200">
 </item>
 <item
 android:drawable="@drawable/icon_frame2"
 android:duration="200">
 </item>
 <item
 android:drawable="@drawable/icon_frame3"
 android:duration="200">
 </item>
 <item
 android:drawable="@drawable/icon_frame4"
 android:duration="200">
 </item>
 <item
 android:drawable="@drawable/icon_frame5"
 android:duration="200">
 </item>
 <item
 android:drawable="@drawable/icon_frame6"
 android:duration="50">
 </item>
</animation-list>

xml幀動(dòng)畫使用代碼:
ivFrame = (ImageView) findViewById(R.id.iv_frame_image);
ivFrame.setImageResource(R.drawable.anim_frame); 
animation = (AnimationDrawable) ivFrame.getDrawable();
animation.setOneShot(false);//循環(huán)
animation.start();

以上就是針對(duì)Android實(shí)現(xiàn)動(dòng)畫效果的全部?jī)?nèi)容,希望大家能夠喜歡。

相關(guān)文章

最新評(píng)論