当前位置: 编程技术>移动开发
Android 四种动画效果的调用实现代码
来源: 互联网 发布时间:2014-10-13
本文导语: (1) main.xml 代码如下:(声明四个按钮控件) XML代码: 代码如下: java代码: 代码如下: import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.view.animation.Animation; import an...
(1) main.xml 代码如下:(声明四个按钮控件)
XML代码:
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代码:
代码如下:
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;
}
}
}
效果图: