Android中启动动画源码讲解
首先是主要代码 的实现 ,去调用 各个xml 配置文件:
MainActivity:
public class MainActivity extends Activity { private ImageView imageView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //获取显示控件ID imageView = (ImageView) findViewById(R.id.imageView1); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } public void animImpl(View v){ //调用 动画的配置文件 Animation animation = AnimationUtils.loadAnimation(this, R.anim.alpha_demo); imageView.startAnimation(animation); } //旋转动画 public void rotate(){ Animation animation = AnimationUtils.loadAnimation(this, R.anim.rotate_demo); imageView.startAnimation(animation); } //缩放动画 public void scaleImpl(){ Animation animation = AnimationUtils.loadAnimation(this, R.anim.scale_demo); imageView.startAnimation(animation); } //移动效果 public void translateImpl(){ //XML文件 /* Animation animation = AnimationUtils.loadAnimation(this, R.anim.translate_demo); animation.setRepeatCount(Animation.INFINITE);*/ /* 第一种 * imageView.setAnimation(animation); animation.start();*/ //第二种 // imageView.startAnimation(animation); //Java代码 TranslateAnimation translateAnimation = new TranslateAnimation(0, 200, 0, 0); translateAnimation.setDuration(2000); imageView.startAnimation(translateAnimation); } //缩放效果 }
<alpha xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:fromAlpha="1.0" android:toAlpha="0.1" android:duration="2000"/> <!-- fromAlpha :起始透明度 toAlpha:结束透明度 1.0表示完全不透明 0.0表示完全透明 -->
补充:移动开发 , Android ,