首先是主要代碼 的實現 ,去調用 各個xml 設定檔:
MainActivity:
public class MainActivity extends Activity {private ImageView imageView;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);//擷取顯示控制項IDimageView = (ImageView) findViewById(R.id.imageView1);}@Overridepublic 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表示完全透明 -->