[英]How do I make a splash screen end animation and start next activity?
我正在用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);
}
}
Intent intent = new Intent();
intent.setClass(getApplicationContext(), NextActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.slide_in_up, R.anim.slide_out_up);
根據您的需求使用Intent
... 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>
謝謝。 我將應用您提到的更改。 但是我遇到了一個錯誤!
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) {
}
});
}
錯誤:
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
謝謝,請在動畫結束后告知下一個活動。
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" />
translation.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
主要活動
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);
}
});
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.