具体代码如下:
淡入淡出
- <?xml version="1.0" encoding="utf-8"?>
- <set xmlns:Android="http://schemas.android.com/apk/res/android" >
- <alpha
- android:duration="3000"
- android:fromAlpha="0.1"
- android:toAlpha="1.0" />
- </set>
旋转效果
- <?xml version="1.0" encoding="utf-8"?>
- <set xmlns:android="http://schemas.android.com/apk/res/android" >
- <rotate
- android:duration="3000"
- android:fromDegrees="0"
- android:pivotX="50%"
- android:pivotY="50%"
- android:toDegrees="+360" />
- </set>
缩放效果
- <?xml version="1.0" encoding="utf-8"?>
- <set xmlns:android="http://schemas.android.com/apk/res/android" >
- <scale
- android:duration="3000"
- android:fillAfter="false"
- android:fromXScale="0.0"
- android:fromYScale="0.0"
- android:interpolator="@android:anim/accelerate_decelerate_interpolator"
- android:pivotX="50%"
- android:pivotY="50%"
- android:toXScale="1"
- android:toYScale="1" />
- </set>
移动效果
- <?xml version="1.0" encoding="utf-8"?>
- <set xmlns:android="http://schemas.android.com/apk/res/android" >
- <translate
- android:duration="3000"
- android:fromXDelta="0"
- android:fromYDelta="0"
- android:interpolator="@android:anim/accelerate_interpolator"
- android:toXDelta="100"
- android:toYDelta="0" />
- </set>
这是使用的xml的形式进行Animation的设定,还可以在java代码中直接写出,而且一个文件可以有多种效果,多种结合方式,更多设置选项还有各子的意义这里就不一一列举出来,自己在网站上都能找到,最后是Activity的代码:
- package sina.CreAmazing.muti_button;
- import android.app.Activity;
- import android.os.Bundle;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.view.animation.AnimationUtils;
- import android.widget.Button;
- public class MutiButtonActivity extends Activity {
- /** Called when the activity is first created. */
- private Button btStart;
- private Button bt1;
- private Button bt2;
- private Button bt3;
- private Button bt4;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- findViews();
- btStart.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- startAnimation();
- }
- });
- }
- private void findViews() {
- // TODO Auto-generated method stub
- btStart = (Button) findViewById(R.id.bt_start);
- bt1 = (Button) findViewById(R.id.bt1);
- bt2 = (Button) findViewById(R.id.bt2);
- bt3 = (Button) findViewById(R.id.bt3);
- bt4 = (Button) findViewById(R.id.bt4);
- }
- private void startAnimation(){
- bt1.startAnimation(AnimationUtils.loadAnimation(this, R.anim.bt_alpha));
- bt2.startAnimation(AnimationUtils.loadAnimation(this, R.anim.bt_rotate));
- bt3.startAnimation(AnimationUtils.loadAnimation(this, R.anim.bt_scale));
- bt4.startAnimation(AnimationUtils.loadAnimation(this, R.anim.bt_translate));
- }
- }
其实只要巧妙的利用Animation就能为应用作出很多很酷效果,在这篇讲到。见 http://www.linuxidc.com/Linux/2012-02/55175.htm
