您好,登錄后才能下訂單哦!
這篇文章將為大家詳細(xì)講解有關(guān)Android中Animation如何使用,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個(gè)參考,希望大家閱讀完這篇文章后對(duì)相關(guān)知識(shí)有一定的了解。
Android使用Animation方法一:在xml中定義動(dòng)畫(huà):
Xml代碼
< ?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="+360"
android:duration="3000" />
< !-- rotate 旋轉(zhuǎn)動(dòng)畫(huà)效果
屬性:interpolator 指定一個(gè)動(dòng)畫(huà)的插入器,用來(lái)控制動(dòng)畫(huà)的速度變化
fromDegrees 屬性為動(dòng)畫(huà)起始時(shí)物件的角度
toDegrees 屬性為動(dòng)畫(huà)結(jié)束時(shí)物件旋轉(zhuǎn)的角度,+代表順時(shí)針
duration 屬性為動(dòng)畫(huà)持續(xù)時(shí)間,以毫秒為單位
-->
< /set>
< ?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="+360"
android:duration="3000" />
< !-- rotate 旋轉(zhuǎn)動(dòng)畫(huà)效果
屬性:interpolator 指定一個(gè)動(dòng)畫(huà)的插入器,用來(lái)控制動(dòng)畫(huà)的速度變化
fromDegrees 屬性為動(dòng)畫(huà)起始時(shí)物件的角度
toDegrees 屬性為動(dòng)畫(huà)結(jié)束時(shí)物件旋轉(zhuǎn)的角度,+代表順時(shí)針
duration 屬性為動(dòng)畫(huà)持續(xù)時(shí)間,以毫秒為單位
-->
< /set>
使用動(dòng)畫(huà)的Java代碼,程序的效果是點(diǎn)擊按鈕,TextView旋轉(zhuǎn)一周:
Java代碼
package com.ray.animation;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.TextView;
public class TestAnimation extends Activity
implements OnClickListener{public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btn = (Button)findViewById(R.id.Button01);
btn.setOnClickListener(this);
}
@Override
public void onClick(View v) {
Animation anim = AnimationUtils.loadAnimation(this,
R.anim.my_rotate_action);findViewById(R.id.TextView01).startAnimation(anim);
}
}
package com.ray.animation;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.TextView;
public class TestAnimation extends Activity
implements OnClickListener{public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btn = (Button)findViewById(R.id.Button01);
btn.setOnClickListener(this);
}
@Override
public void onClick(View v) {
Animation anim = AnimationUtils.loadAnimation(this,
R.anim.my_rotate_action);findViewById(R.id.TextView01).startAnimation(anim);
}
}
Android使用Animation方法二:直接在代碼中定義動(dòng)畫(huà)(效果跟方法一類(lèi)似):
Java代碼
package com.ray.animation;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.widget.Button;
public class TestAnimation extends Activity
implements OnClickListener{public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btn = (Button)findViewById(R.id.Button);
btn.setOnClickListener(this);
}
public void onClick(View v) {
Animation anim = null;
anim = new RotateAnimation(0.0f,+360.0f);
anim.setInterpolator(new AccelerateDecelerateInterpolator());
anim.setDuration(3000);
findViewById(R.id.TextView01).startAnimation(anim);
}
}
關(guān)于Android中Animation如何使用就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。