2016-09-01 92 views
0

我正在開發Android中的移動應用程序。 我有一個初始動畫;之後,控制應該轉移到下一個活動。轉移不會發生。 我哪裏錯了?如何製作啓動畫面結束動畫並開始下一個活動?

public class MainActivity extends Activity { 
    public void onAttachedToWindow() { 
     super.onAttachedToWindow(); 
     Window window = getWindow(); 
     window.setFormat(PixelFormat.RGBA_8888); 

    } 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     getWindow().getDecorView().setSystemUiVisibility(
       View.SYSTEM_UI_FLAG_LAYOUT_STABLE 
         | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION 
         | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN 
         | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION 
         | View.SYSTEM_UI_FLAG_FULLSCREEN 
         | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); 
     StartAnimations(); 



    } 

    private void StartAnimations() { 
     Animation anim = AnimationUtils.loadAnimation(this, R.anim.alpha); 
     anim.reset(); 
     LinearLayout l=(LinearLayout) findViewById(R.id.lin_lay); 
     l.clearAnimation(); 
     l.startAnimation(anim); 

     anim = AnimationUtils.loadAnimation(this, R.anim.translate); 
     anim.reset(); 
     ImageView iv = (ImageView) findViewById(R.id.logo); 
     iv.clearAnimation(); 
     iv.startAnimation(anim); 

    } 



} 
+0

改進語法 – Prune

回答

0

感謝 請動畫走結束後,通知下一個活動。

alpha.xml

<?xml version="1.0" encoding="utf-8"?> 
    <alpha 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:fromAlpha="0.0" 
     android:toAlpha="1.0" 
     android:duration="3000" /> 

translate.xml

<?xml version="1.0" encoding="utf-8"?> 
<set 
    xmlns:android="http://schemas.android.com/apk/res/android"> 
    <translate 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:fromXDelta="0%" 
     android:toXDelta="0%" 
     android:fromYDelta="200%" 
     android:toYDelta="0%" 
     android:duration="2000" 
     android:zAdjustment="top" /> 
</set 

Mainactivity

public class MainActivity extends Activity { 
    public void onAttachedToWindow() { 
     super.onAttachedToWindow(); 
     Window window = getWindow(); 
     window.setFormat(PixelFormat.RGBA_8888); 

    } 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     getWindow().getDecorView().setSystemUiVisibility(
       View.SYSTEM_UI_FLAG_LAYOUT_STABLE 
         | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION 
         | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN 
         | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION 
         | View.SYSTEM_UI_FLAG_FULLSCREEN 
         | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); 
     StartAnimations(); 


    } 

    private void StartAnimations() { 

     LinearLayout l = (LinearLayout) findViewById(R.id.lin_lay); 
     ImageView iv = (ImageView) findViewById(R.id.logo); 

     Animation anim = AnimationUtils.loadAnimation(this, R.anim.alpha); 
     l.startAnimation(anim); 

     Animation anim2 = AnimationUtils.loadAnimation(this, R.anim.translate); 
     iv.startAnimation(anim2); 

     anim2.setAnimationListener(new Animation.AnimationListener() { 
      @Override 
      public void onAnimationStart(Animation animation) { 

      } 

      @Override 
      public void onAnimationEnd(Animation animation) { 
       l.clearAnimation(); 
       iv.clearAnimation(); 

       //open your second activity 

      } 

      @Override 
      public void onAnimationRepeat(Animation animation) { 
       Intent in = new Intent(getApplicationContext(),Home.class); 
       startActivity(in); 

      } 

     }); 
    } 
0
Intent intent = new Intent(); 
     intent.setClass(getApplicationContext(), NextActivity.class); 
     startActivity(intent); 
     overridePendingTransition(R.anim.slide_in_up, R.anim.slide_out_up); 

使用意向爲您的要求

... slide_out_up.xml

<set xmlns:android="http://schemas.android.com/apk/res/android" 
android:shareInterpolator="false" > 

<translate 
    android:duration="400" 
    android:fromYDelta="0%" 
    android:toYDelta="-100%" /> 

<alpha 
    android:duration="400" 
    android:fromAlpha="1" 
    android:toAlpha="0" /> 

</set> 

slide_in_up.xml

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android" 
android:shareInterpolator="false" > 

<translate 
    android:duration="400" 
    android:fromYDelta="100%" 
    android:toYDelta="0%" /> 

<alpha 
    android:duration="400" 
    android:fromAlpha="0" 
    android:toAlpha="1" /> 

</set> 
+0

給予好評如果u [R滿意的答案。 – Android

0

謝謝。 我應用您提到的更改。 但我遇到了一個錯誤!

public class MainActivity extends Activity { 
    public void onAttachedToWindow() { 
     super.onAttachedToWindow(); 
     Window window = getWindow(); 
     window.setFormat(PixelFormat.RGBA_8888); 

    } 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     getWindow().getDecorView().setSystemUiVisibility(
       View.SYSTEM_UI_FLAG_LAYOUT_STABLE 
         | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION 
         | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN 
         | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION 
         | View.SYSTEM_UI_FLAG_FULLSCREEN 
         | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); 
     StartAnimations(); 


    } 

    private void StartAnimations() { 

     LinearLayout l = (LinearLayout) findViewById(R.id.lin_lay); 
     ImageView iv = (ImageView) findViewById(R.id.logo); 

     Animation anim = AnimationUtils.loadAnimation(this, R.anim.alpha); 
     l.startAnimation(anim); 

     Animation anim2 = AnimationUtils.loadAnimation(this, R.anim.translate); 
     iv.startAnimation(anim2); 

     anim2.setAnimationListener(new Animation.AnimationListener() { 
      @Override 
      public void onAnimationStart(Animation animation) { 

      } 

      @Override 
      public void onAnimationEnd(Animation animation) { 
       l.clearAnimation(); 
       iv.clearAnimation(); 

       //open your second activity 

      } 

      @Override 
      public void onAnimationRepeat(Animation animation) { 

      } 

    }); 
    } 

Eror:

Error:Execution failed for task ':app:compileDebugJavaWithJavac'. 
> Compilation failed; see the compiler error output for details. 
Error:(72, 6) error: reached end of file while parsing 
:app:compileDebugJavaWithJavac FAILED 
+0

你在Splash屏幕上點擊任何API嗎? –

+0

api: compileSdkVersion 23 buildToolsVersion「23.0.3」 –

+0

你可以請我發佈你的alpha.xml,translate.xml和你正在寫入onAnimationEnd()代碼的代碼嗎? –