Android 四種動(dòng)畫效果的調(diào)用實(shí)現(xiàn)代碼
更新時(shí)間:2013年01月21日 12:05:07 作者:
在這里, 我將每種動(dòng)畫分別應(yīng)用于四個(gè)按鈕為例,需要的朋友可以參考下
(1) main.xml 代碼如下:(聲明四個(gè)按鈕控件)
XML代碼:
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
android:id="@+id/widget32"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<TextView
android:id="@+id/widget29"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
android:layout_x="0px"
android:layout_y="0px"
>
</TextView>
<Button
android:id="@+id/button_Alpha"
android:layout_width="150px"
android:layout_height="150px"
android:text="Alpha動(dòng)畫"
android:textSize="50px"
android:layout_x="0px"
android:layout_y="30px">
</Button>
<Button
android:id="@+id/button_Scale"
android:layout_width="150px"
android:layout_height="150px"
android:text="Scale動(dòng)畫"
android:textSize="50px"
android:layout_x="0px"
android:layout_y="180px">
</Button>
<Button
android:layout_width="150px"
android:layout_height="150px"
android:text="Translate動(dòng)畫"
android:layout_x="161px"
android:layout_y="30px"
android:textSize="30px"
android:id="@+id/button_Translate">
</Button>
<Button
android:id="@+id/button_Rotate"
android:layout_width="150px"
android:layout_height="150px"
android:text="Rotate動(dòng)畫"
android:layout_y="180px"
android:layout_x="161px"
android:textSize="44px">
</Button>
</AbsoluteLayout>
java代碼:
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;
public class myActionAnimation extends Activity implements OnClickListener {
/** Called when the activity is first created. */
private Button button_alpha;
private Button button_scale;
private Button button_translate;
private Button button_rotate;
private Animation myAnimation_Alpha;
private Animation myAnimation_Scale;
private Animation myAnimation_Translate;
private Animation myAnimation_Rotate;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
button_alpha = (Button) findViewById(R.id.button_Alpha);
button_alpha.setOnClickListener(this);
button_scale = (Button) findViewById(R.id.button_Scale);
button_scale.setOnClickListener(this);
button_translate = (Button) findViewById(R.id.button_Translate);
button_translate.setOnClickListener(this);
button_rotate = (Button) findViewById(R.id.button_Rotate);
button_rotate.setOnClickListener(this);
}
public void onClick(View button) {
// TODO Auto-generated method stub
switch (button.getId()) {
case R.id.button_Alpha: {
myAnimation_Alpha = AnimationUtils.loadAnimation(this,R.layout.my_alpha_action);
button_alpha.startAnimation(myAnimation_Alpha);
}
break;
case R.id.button_Scale: {
myAnimation_Scale= AnimationUtils.loadAnimation(this,R.layout.my_scale_action);
button_scale.startAnimation(myAnimation_Scale);
}
break;
case R.id.button_Translate: {
myAnimation_Translate= AnimationUtils.loadAnimation(this,R.layout.my_translate_action);
button_translate.startAnimation(myAnimation_Translate);
}
break;
case R.id.button_Rotate: {
myAnimation_Rotate= AnimationUtils.loadAnimation(this,R.layout.my_rotate_action);
button_rotate.startAnimation(myAnimation_Rotate);
}
break;
default:
break;
}
}
}
效果圖:
XML代碼:
復(fù)制代碼 代碼如下:
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
android:id="@+id/widget32"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<TextView
android:id="@+id/widget29"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
android:layout_x="0px"
android:layout_y="0px"
>
</TextView>
<Button
android:id="@+id/button_Alpha"
android:layout_width="150px"
android:layout_height="150px"
android:text="Alpha動(dòng)畫"
android:textSize="50px"
android:layout_x="0px"
android:layout_y="30px">
</Button>
<Button
android:id="@+id/button_Scale"
android:layout_width="150px"
android:layout_height="150px"
android:text="Scale動(dòng)畫"
android:textSize="50px"
android:layout_x="0px"
android:layout_y="180px">
</Button>
<Button
android:layout_width="150px"
android:layout_height="150px"
android:text="Translate動(dòng)畫"
android:layout_x="161px"
android:layout_y="30px"
android:textSize="30px"
android:id="@+id/button_Translate">
</Button>
<Button
android:id="@+id/button_Rotate"
android:layout_width="150px"
android:layout_height="150px"
android:text="Rotate動(dòng)畫"
android:layout_y="180px"
android:layout_x="161px"
android:textSize="44px">
</Button>
</AbsoluteLayout>
java代碼:
復(fù)制代碼 代碼如下:
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;
public class myActionAnimation extends Activity implements OnClickListener {
/** Called when the activity is first created. */
private Button button_alpha;
private Button button_scale;
private Button button_translate;
private Button button_rotate;
private Animation myAnimation_Alpha;
private Animation myAnimation_Scale;
private Animation myAnimation_Translate;
private Animation myAnimation_Rotate;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
button_alpha = (Button) findViewById(R.id.button_Alpha);
button_alpha.setOnClickListener(this);
button_scale = (Button) findViewById(R.id.button_Scale);
button_scale.setOnClickListener(this);
button_translate = (Button) findViewById(R.id.button_Translate);
button_translate.setOnClickListener(this);
button_rotate = (Button) findViewById(R.id.button_Rotate);
button_rotate.setOnClickListener(this);
}
public void onClick(View button) {
// TODO Auto-generated method stub
switch (button.getId()) {
case R.id.button_Alpha: {
myAnimation_Alpha = AnimationUtils.loadAnimation(this,R.layout.my_alpha_action);
button_alpha.startAnimation(myAnimation_Alpha);
}
break;
case R.id.button_Scale: {
myAnimation_Scale= AnimationUtils.loadAnimation(this,R.layout.my_scale_action);
button_scale.startAnimation(myAnimation_Scale);
}
break;
case R.id.button_Translate: {
myAnimation_Translate= AnimationUtils.loadAnimation(this,R.layout.my_translate_action);
button_translate.startAnimation(myAnimation_Translate);
}
break;
case R.id.button_Rotate: {
myAnimation_Rotate= AnimationUtils.loadAnimation(this,R.layout.my_rotate_action);
button_rotate.startAnimation(myAnimation_Rotate);
}
break;
default:
break;
}
}
}
效果圖:

您可能感興趣的文章:
- Android編程簡單實(shí)現(xiàn)雷達(dá)掃描效果
- Android仿微信雷達(dá)輻射搜索好友(邏輯清晰實(shí)現(xiàn)簡單)
- Android 吸入動(dòng)畫效果實(shí)現(xiàn)分解
- Android動(dòng)畫之3D翻轉(zhuǎn)效果實(shí)現(xiàn)函數(shù)分析
- Android圖片翻轉(zhuǎn)動(dòng)畫簡易實(shí)現(xiàn)代碼
- Android 3D旋轉(zhuǎn)動(dòng)畫效果實(shí)現(xiàn)分解
- Android啟動(dòng)畫面的實(shí)現(xiàn)方法
- Android動(dòng)畫之雷達(dá)掃描效果
相關(guān)文章
Android實(shí)現(xiàn)手機(jī)振動(dòng)設(shè)置的方法
這篇文章主要介紹了Android實(shí)現(xiàn)手機(jī)振動(dòng)設(shè)置的方法,涉及Android頁面布局、屬性及功能設(shè)置的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-09-09Android4.0.x Home鍵事件攔截監(jiān)聽的方法
這篇文章主要介紹了Android4.0.x Home鍵事件攔截監(jiān)聽的方法,對比分析了2.3.x的實(shí)現(xiàn)方法,分析了4.0.x實(shí)現(xiàn)Home鍵事件攔截監(jiān)聽的相關(guān)技巧,需要的朋友可以參考下2016-02-02Android利用CountDownTimer實(shí)現(xiàn)驗(yàn)證碼倒計(jì)時(shí)效果實(shí)例
這篇文章主要給大家介紹了關(guān)于Android如何利用CountDownTimer實(shí)現(xiàn)驗(yàn)證碼倒計(jì)時(shí)效果的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。2017-10-10詳解Android:向服務(wù)器提供數(shù)據(jù)之get、post方式
本篇文章主要介紹了詳解Android:向服務(wù)器提供數(shù)據(jù)之get、post方式,具有一定的參考價(jià)值,有興趣的可以了解一下。2017-03-03Android實(shí)現(xiàn)評論欄隨Recyclerview滑動(dòng)左右移動(dòng)
這篇文章主要介紹了Android實(shí)現(xiàn)評論欄隨Recyclerview滑動(dòng)左右移動(dòng)效果,仿約會(huì)吧應(yīng)用詳情頁實(shí)現(xiàn),感興趣的小伙伴們可以參考一下2016-05-05Android實(shí)現(xiàn)拖動(dòng)小球跟隨手指移動(dòng)效果
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)拖動(dòng)小球跟隨手指移動(dòng)效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-03-03