[英]How do I make a splash screen end animation and start next activity?
I'm developing a mobile application in Android. 我正在用Android开发移动应用程序。 I have an initial animation;
我有一个初始动画; after that, control should transfer to the next activity.
之后,控制权应转移到下一个活动。 The transfer doesn't happen.
转移不会发生。 Where did I go wrong?
我哪里做错了?
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);
use Intent for your requirement 根据您的需求使用Intent
... slide_out_up.xml ... 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 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>
thank you. 谢谢。 I apply the changes you mentioned.
我将应用您提到的更改。 But I was met with an error !!!
但是我遇到了一个错误!
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
Thanks Please advise the next activity after the end of the animation to go. 谢谢,请在动画结束后告知下一个活动。
alpha.xml 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 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
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);
}
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.