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

Android開發(fā)之圖形圖像與動(dòng)畫(三)Animation效果的XML實(shí)現(xiàn)

 更新時(shí)間:2013年01月28日 11:46:09   作者:  
使用XML來定義Tween Animation動(dòng)畫的XML文件在工程中res/anim目錄,這個(gè)文件必須包含一個(gè)根元素,感興趣的友可以了解一下,希望本文對(duì)你有所幫助
使用XML來定義Tween Animation
動(dòng)畫的XML文件在工程中res/anim目錄,這個(gè)文件必須包含一個(gè)根元素,可以使<alpha><scale> <translate> <rotate>插值元素或者是把上面的元素都放入<set>元素組中,默認(rèn)情況下,所以的動(dòng)畫指令都是同時(shí)發(fā)生的,為了讓他們按序列發(fā)生,需要設(shè)置一個(gè)特殊的屬性startOffset。動(dòng)畫的指令定義了你想要發(fā)生什么樣的轉(zhuǎn)換,當(dāng)他們發(fā)生了,應(yīng)該執(zhí)行多長(zhǎng)時(shí)間,轉(zhuǎn)換可以是連續(xù)的也可以使同時(shí)的。例如,你讓文本內(nèi)容從左邊移動(dòng)到右邊,然后旋轉(zhuǎn)180度,或者在移動(dòng)的過程中同時(shí)旋轉(zhuǎn),沒個(gè)轉(zhuǎn)換需要設(shè)置一些特殊的參數(shù)(開始和結(jié)束的大小尺寸的大小變化,開始和結(jié)束的旋轉(zhuǎn)角度等等,也可以設(shè)置些基本的參數(shù)(例如,開始時(shí)間與周期),如果讓幾個(gè)轉(zhuǎn)換同時(shí)發(fā)生,可以給它們?cè)O(shè)置相同的開始時(shí)間,如果按序列的話,計(jì)算開始時(shí)間加上其周期。
Tween Animation共同的節(jié)點(diǎn)屬性

屬性[類型] 功能 備注
Duration[long] 屬性為動(dòng)畫持續(xù)時(shí)間 時(shí)間以毫秒為單位
fillAfter [boolean] 當(dāng)設(shè)置為true ,該動(dòng)畫轉(zhuǎn)化在動(dòng)畫結(jié)束后被應(yīng)用
fillBefore[boolean] 當(dāng)設(shè)置為true ,該動(dòng)畫轉(zhuǎn)化在動(dòng)畫開始前被應(yīng)用

interpolator

指定一個(gè)動(dòng)畫的插入器 有一些常見的插入器
accelerate_decelerate_interpolator
加速-減速 動(dòng)畫插入器
accelerate_interpolator
加速-動(dòng)畫插入器
decelerate_interpolator
減速- 動(dòng)畫插入器
其他的屬于特定的動(dòng)畫效果
repeatCount[int] 動(dòng)畫的重復(fù)次數(shù)
RepeatMode[int] 定義重復(fù)的行為 1:重新開始  2:plays backward
startOffset[long] 動(dòng)畫之間的時(shí)間間隔,從上次動(dòng)畫停多少時(shí)間開始執(zhí)行下個(gè)動(dòng)畫
zAdjustment[int] 定義動(dòng)畫的Z Order的改變 0:保持Z Order不變
1:保持在最上層
-1:保持在最下層

表二

XML節(jié)點(diǎn) 功能說明
alpha 漸變透明度動(dòng)畫效果
<alpha
android:fromAlpha=”0.1″
android:toAlpha=”1.0″
android:duration=”3000″ />
fromAlpha

屬性為動(dòng)畫起始時(shí)透明度

0.0表示完全透明
1.0表示完全不透明
以上值取0.0-1.0之間的float數(shù)據(jù)類型的數(shù)字

duration為動(dòng)畫持續(xù)時(shí)間,ms單位

toAlpha

屬性為動(dòng)畫結(jié)束時(shí)透明度

表三

scale 漸變尺寸伸縮動(dòng)畫效果
<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:startOffset=“700”
android:duration=”700″
android:repeatCount=”10″ />
fromXScale[float] fromYScale[float] 為動(dòng)畫起始時(shí),X、Y坐標(biāo)上的伸縮尺寸 0.0表示收縮到?jīng)]有
1.0表示正常無伸縮
值小于1.0表示收縮
值大于1.0表示放大
toXScale [float]
toYScale[float]
為動(dòng)畫結(jié)束時(shí),X、Y坐標(biāo)上的伸縮尺寸
pivotX[float]
pivotY[float]
為動(dòng)畫相對(duì)于物件的X、Y坐標(biāo)的開始位置 屬性值說明:從0%-100%中取值,50%為物件的X或Y方向坐標(biāo)上的中點(diǎn)位置

表四
translate 畫面轉(zhuǎn)換位置移動(dòng)動(dòng)畫效果
<translate
android:fromXDelta=”30″
android:toXDelta=”-80″
android:fromYDelta=”30″
android:toYDelta=”300″
android:duration=”2000″ />
fromXDelta
toXDelta
為動(dòng)畫、結(jié)束起始時(shí) X坐標(biāo)上的位置
fromYDelta
toYDelta
為動(dòng)畫、結(jié)束起始時(shí) Y坐標(biāo)上的位置

表五
rotate 畫面轉(zhuǎn)移旋轉(zhuǎn)動(dòng)畫效果
<rotate
android:interpolator=”@android:anim/accelerate_decelerate_interpolator”
android:fromDegrees=”0″
android:toDegrees=”+350″
android:pivotX=”50%”
android:pivotY=”50%”
android:duration=”3000″ />
fromDegrees 為動(dòng)畫起始時(shí)物件的角度 說明
當(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))
toDegrees 屬性為動(dòng)畫結(jié)束時(shí)物件旋轉(zhuǎn)的角度 可以大于360度
pivotX
pivotY
為動(dòng)畫相對(duì)于物件的X、Y坐標(biāo)的開始位 說明:以上兩個(gè)屬性值 從0%-100%中取值
50%為物件的X或Y方向坐標(biāo)上的中點(diǎn)位置


下面給出一個(gè)完整的XML定義(SDK提供)
復(fù)制代碼 代碼如下:

<SPAN style="FONT-SIZE: 18px"><set android:shareInterpolator="false" xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:fromXScale="1.0"
android:toXScale="1.4"
android:fromYScale="1.0"
android:toYScale="0.6"
android:pivotX="50%"
android:pivotY="50%"
android:fillAfter="false"
android:duration="700" />
<set android:interpolator="@android:anim/decelerate_interpolator">
<scale
android:fromXScale="1.4"
android:toXScale="0.0"
android:fromYScale="0.6"
android:toYScale="0.0"
android:pivotX="50%"
android:pivotY="50%"
android:startOffset="700"
android:duration="400"
android:fillBefore="false" />
<rotate
android:fromDegrees="0"
android:toDegrees="-45"
android:toYScale="0.0"
android:pivotX="50%"
android:pivotY="50%"
android:startOffset="700"
android:duration="400" />
</set>
</set></SPAN>

一下是實(shí)現(xiàn)的一個(gè)實(shí)例的截圖:
pic
所用到的xml文件如下:
1.alpha
復(fù)制代碼 代碼如下:

<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:startOffset="500"
android:duration="2000"
/>
</set>

2.rotate
復(fù)制代碼 代碼如下:

<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:duration="2000"
/>
</set>

3.scale
復(fù)制代碼 代碼如下:

<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.0"
android:fromYScale="0.0"
android:toYScale="1.0"
android:pivotX="50%"
android:pivotY="50%"
android:fillAfter="false"
android:duration="2000"
/>
</set>

4.translate
復(fù)制代碼 代碼如下:

<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="10"
android:toXDelta="100"
android:fromYDelta="10"
android:toYDelta="100"
android:duration="2000"
/>
</set>

具體的實(shí)現(xiàn)源代碼如下:
復(fù)制代碼 代碼如下:

public class Animation_XML_Activity extends Activity {
private Button button1;
private Button button2;
private Button button3;
private Button button4;
private ImageView imageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_animation__xml_);
button1=(Button)findViewById(R.id.button_alpha);
button2=(Button)findViewById(R.id.button_rotate);
button3=(Button)findViewById(R.id.button_scale);
button4=(Button)findViewById(R.id.button_translate);
imageView=(ImageView)findViewById(R.id.imageview);
button1.setOnClickListener(new MyButton());
button2.setOnClickListener(new MyButton());
button3.setOnClickListener(new MyButton());
button4.setOnClickListener(new MyButton());
}
class MyButton implements OnClickListener{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.button_alpha:
Alpha();
break;
case R.id.button_rotate:
Rotate();
break;
case R.id.button_scale:
Scale();
break;
case R.id.button_translate:
Translate();
break;
default:
break;
}
}

}
public void Alpha() {
Animation animation=AnimationUtils.loadAnimation(Animation_XML_Activity.this, R.anim.alpha);
imageView.startAnimation(animation);
}
public void Rotate() {
Animation animation=AnimationUtils.loadAnimation(Animation_XML_Activity.this, R.anim.rotate);
imageView.startAnimation(animation);
}
public void Scale() {
Animation animation=AnimationUtils.loadAnimation(Animation_XML_Activity.this, R.anim.scale);
imageView.startAnimation(animation);
}
public void Translate() {
Animation animation=AnimationUtils.loadAnimation(Animation_XML_Activity.this, R.anim.translate);
imageView.startAnimation(animation);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_animation__xml_, menu);
return true;
}
}

相關(guān)文章

最新評(píng)論