歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android進入應用程序時的動畫實現【附源碼】

Android進入應用程序時的動畫實現【附源碼】

日期:2017/3/1 10:19:19   编辑:Linux編程

相信玩過Android應用的同學都看過進入應用程序時出現的短暫動畫,如果是開發者,會想想該如何實現吧,當然,這個不是什麼很有技術含量的事情。

思路很簡單:

1,首先在main.xml裡面放置一個ImageView,剛開始設置為不可見
2,在Main Activity的onCreate裡面放一個alpha動畫
這樣就實現了一個進入應用程序的主界面動畫了。

代碼如下
HomeDemoActivity.java

  1. public class HomeDemoActivity extends Activity {
  2. ImageView homeImage;
  3. /** Called when the activity is first created. */
  4. @Override
  5. public void onCreate(Bundle savedInstanceState) {
  6. super.onCreate(savedInstanceState);
  7. setContentView(R.layout.main);
  8. homeImage = (ImageView) findViewById(R.id.homeimg);
  9. AlphaAnimation alphaAnimation = new AlphaAnimation((float) 0.1, 1);
  10. alphaAnimation.setDuration(3000);//設定動畫時間
  11. alphaAnimation.setAnimationListener(new AnimationListener() {
  12. @Override
  13. public void onAnimationStart(Animation animation) {
  14. }
  15. @Override
  16. public void onAnimationRepeat(Animation animation) {
  17. }
  18. @Override
  19. public void onAnimationEnd(Animation animation) {
  20. homeImage.setVisibility(View.GONE);
  21. }
  22. });
  23. homeImage.setAnimation(alphaAnimation);
  24. homeImage.setVisibility(View.VISIBLE);
  25. }
  26. }
Copyright © Linux教程網 All Rights Reserved