XML中
| 屬性 |
解釋 |
| alpha |
漸變透明度動(dòng)畫效果 |
| scale |
漸變尺寸伸縮動(dòng)畫效果 |
| translate |
畫面轉(zhuǎn)換位置移動(dòng)動(dòng)畫效果 |
| rotate |
畫面轉(zhuǎn)移旋轉(zhuǎn)動(dòng)畫效果 |
JAVA代碼中
| 屬性 |
解釋 |
| AlphaAnimation |
漸變透明度動(dòng)畫效果 |
| ScaleAnimation |
漸變尺寸伸縮動(dòng)畫效果 |
| TranslateAnimation |
畫面轉(zhuǎn)換位置移動(dòng)動(dòng)畫效果 |
| RotateAnimation |
畫面轉(zhuǎn)移旋轉(zhuǎn)動(dòng)畫效果 |
Android動(dòng)畫模式
漸變動(dòng)畫
| XML中 |
JavaCode中 |
| alpha |
AlphaAnimation |
| scale |
ScaleAnimation |
畫面轉(zhuǎn)換動(dòng)畫
| XML中 |
JavaCode中 |
| translate |
TranslateAnimation |
| rotate |
RotateAnimation |
動(dòng)畫的XML定義格式
xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha/>
<scale/>
<translate/>
<rotate/>
</set>
Android動(dòng)畫解析-XML
alpha
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<alpha
android:fromAlpha="0.1"
android:toAlpha="1.0"
android:duration="3000"
/>
<!-- 透明度控制動(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í)間
說明:
時(shí)間以毫秒為單位
-->
</set>
scale
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:interpolator=
"@android:anim/accelerate_decelerate_interpolator"
android:fromXScale="0.0"
android:toXScale="1.4"
android:fromYScale="0.0"
android:toYScale="1.4"
android:pivotX="50%"
android:pivotY="50%"
android:fillAfter="false"
android:duration="700" />
</set>
<!-- 尺寸伸縮動(dòng)畫效果 scale
屬性:interpolator 指定一個(gè)動(dòng)畫的插入器
在我試驗(yàn)過程中,使用android.res.anim中的資源時(shí)候發(fā)現(xiàn)
有三種動(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)畫起始時(shí)Y坐標(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%中取值
50%為物件的X或Y方向坐標(biāo)上的中點(diǎn)位置
長整型值:
duration 屬性為動(dòng)畫持續(xù)時(shí)間
說明: 時(shí)間以毫秒為單位
布爾型值:
fillAfter 屬性 當(dāng)設(shè)置為true ,該動(dòng)畫轉(zhuǎn)化在動(dòng)畫結(jié)束后被應(yīng)用
-->
translate
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="30"
android:toXDelta="-80"
android:fromYDelta="30"
android:toYDelta="300"
android:duration="2000"
/>
<!-- 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)上的位置
toYDelta 屬性為動(dòng)畫結(jié)束時(shí) Y坐標(biāo)上的位置
注意:
沒有指定fromXType toXType fromYType toYType 時(shí)候,
默認(rèn)是以自己為相對(duì)參照物
長整型值:
duration 屬性為動(dòng)畫持續(xù)時(shí)間
說明: 時(shí)間以毫秒為單位
-->
</set>
rotate
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:fromDegrees="0"
android:toDegrees="+350"
android:pivotX="50%"
android:pivotY="50%"
android:duration="3000" />
<!-- rotate 旋轉(zhuǎn)動(dòng)畫效果
屬性:interpolator 指定一個(gè)動(dòng)畫的插入器
在我試驗(yàn)過程中,使用android.res.anim中的資源時(shí)候發(fā)現(xiàn)
有三種動(dòng)畫插入器:
accelerate_decelerate_interpolator 加速-減速 動(dòng)畫插入器
accelerate_interpolator 加速-動(dòng)畫插入器
decelerate_interpolator 減速- 動(dòng)畫插入器
其他的屬于特定的動(dòng)畫效果
浮點(diǎn)數(shù)型值:
fromDegrees 屬性為動(dòng)畫起始時(shí)物件的角度
toDegrees 屬性為動(dòng)畫結(jié)束時(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))
(正數(shù)from——to負(fù)數(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)位置
長整型值:
duration 屬性為動(dòng)畫持續(xù)時(shí)間
說明: 時(shí)間以毫秒為單位
-->
</set>
使用XML中的動(dòng)畫
public static Animation loadAnimation (Context context, int id)
//第一個(gè)參數(shù)Context為程序的上下文
//第二個(gè)參數(shù)id為動(dòng)畫XML文件的引用
//例子:
myAnimation= AnimationUtils.loadAnimation(this,R.anim.my_action);
//使用AnimationUtils類的靜態(tài)方法loadAnimation()來加載XML中的動(dòng)畫XML文件
在Java中定義動(dòng)畫
//在代碼中定義 動(dòng)畫實(shí)例對(duì)象
private Animation myAnimation_Alpha;
private Animation myAnimation_Scale;
private Animation myAnimation_Translate;
private Animation myAnimation_Rotate;
//根據(jù)各自的構(gòu)造方法來初始化一個(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);
Android動(dòng)畫解析 java代碼
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)上的伸縮尺寸
/*說明:
以上四種屬性值
0.0表示收縮到?jīng)]有
1.0表示正常無伸縮
值小于1.0表示收縮
值大于1.0表示放大
*/
//第五個(gè)參數(shù)pivotXType為動(dòng)畫在X軸相對(duì)于物件位置類型
//第六個(gè)參數(shù)pivotXValue為動(dòng)畫相對(duì)于物件的X坐標(biāo)的開始位置
//第七個(gè)參數(shù)pivotXType為動(dòng)畫在Y軸相對(duì)于物件位置類型
//第八個(gè)參數(shù)pivotYValue為動(dòng)畫相對(duì)于物件的Y坐標(biāo)的開始位置
myAnimation_Scale =new ScaleAnimation(0.0f, 1.4f, 0.0f, 1.4f,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
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)的開始位置
//第五個(gè)參數(shù)pivotXType為動(dòng)畫在Y軸相對(duì)于物件位置類型
//第六個(gè)參數(shù)pivotYValue為動(dòng)畫相對(duì)于物件的Y坐標(biāo)的開始位置
myAnimation_Rotate=new RotateAnimation(0.0f, +350.0f,
Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF, 0.5f);