Android中啟動動畫源碼講解

來源:互聯網
上載者:User

首先是主要代碼 的實現 ,去調用 各個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表示完全透明  -->

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.