2011-05-23 51 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(); 
     } 
    }