2011-05-23 50 views
1

我有一個通過單擊網頁中的鏈接啓動的應用程序。Android:通過動畫啓動應用程序

沒問題,工作正常。

但是,應用程序主屏幕只是有點碰撞瀏覽器。我想添加一些動畫。也許它可以淡入或什麼東西。我已經在ImageView上完成補間動畫,但不知道如何完成佈局屏幕。有任何想法嗎?

+0

咳咳......哪些代碼? – Phonon 2011-05-23 18:56:23

+0

@Phonon:採取了點。編輯問題以使其更清晰:-) – OceanBlue 2011-05-23 19:02:00

回答

9

我想你可以簡單地使用AlphaAnimation,並將其應用到你的活動這樣的佈局,在onCreate方法:

super.onCreate(savedInstace); 
this.setContentView(R.layout.main); 
LinearLayout layout = (LinearLayout) findViewById(R.id.idLayout); 
AlphaAnimation animation = new AlphaAnimation(0.0f , 1.0f) ; 
animation.setFillAfter(true); 
animation.setDuration(1200); 
//apply the animation (fade In) to your LAyout 
layout.startAnimation(animation); 
+0

謝謝!完美的作品。 – OceanBlue 2011-05-23 21:47:52

+0

歡迎來到OceanBlue,我們來幫助您:) – Houcine 2011-05-23 22:35:11

1

此代碼來自我的一個項目。隨意使用它在你的。您的活動應擴展它,並按照HOWTO中的說明進行操作。

/** 
    * FadedActivity is a subclass of Activity. The difference with a 
    * standard activity is the fade in/out animation launched when 
    * the activity begins/ends. 
    * 
    * <p> 
    * HOWTO: 
    * <ul> 
    * <li>layout's main layer must have android:id="root" 
    * <li>derived class must call FadedActivity's super.onCreate() instead of Activity's 
    * <li>use finishFade() instead of finish() 
    * </ul> 
    * 
    * @author  Joel 
    * @version  1.0 
    * @since  1.0 
    */ 

    public static class FadedActivity extends Activity { 

     private static final int FADEIN_DELAY_MS = 1000; 
     private static final int FADEOUT_DELAY_MS = 500; 

     private View root; 

     private void runFadeAnimationOn(Activity ctx, View target, boolean in, int delay) { 
      int start, finish; 
      if (in) { 
       start = 0; 
       finish = 1; 
      } else { 
       start = 1; 
       finish = 0; 
      } 
      AlphaAnimation fade = new AlphaAnimation(start, finish); 
      fade.setDuration(delay); 
      fade.setFillAfter(true); 
      target.startAnimation(fade); 
     }  

     public void onCreate(Bundle savedInstanceState, int layoutId) { 
      super.onCreate(savedInstanceState); 
      setContentView(layoutId); 
      root = (View)findViewById(R.id.root); 
      runFadeAnimationOn(this, root, true, FADEIN_DELAY_MS); 
     } 

     public void finishFade() { 
      final int delay = FADEOUT_DELAY_MS; 
      runFadeAnimationOn(this, root, false, delay); 
      new Thread(new Runnable() { 
       @Override 
       public void run() { 
        try { 
         Thread.sleep(delay); 
        } catch (InterruptedException e) { 
         e.printStackTrace(); 
        } 
        FadedActivity.super.finish(); 
       } 
      }).start(); 
     } 
    }