I’m working on my first Android project, and I’m starting off by making a simple splash screen that fades to black before the main menu is revealed. So far it works. The problem is right after the image fades out, it pops back up for a split second before showing the main menu.
Here’s the code for SplashActivity.java:
public class SplashActivity extends Activity
{
LinearLayout mLinearLayout;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
mLinearLayout = new LinearLayout(this);
ImageView i = new ImageView(this);
i.setImageResource(R.drawable.splash);
mLinearLayout.addView(i);
setContentView(mLinearLayout);
Animation fade = AnimationUtils.loadAnimation(this, R.anim.fade_out);
i.startAnimation(fade);
fade.setAnimationListener(new AnimationListener() {
public void onAnimationEnd(Animation animation)
{
startActivity(new Intent(SplashActivity.this, MenuActivity.class));
SplashActivity.this.finish();
}
public void onAnimationRepeat(Animation arg0) {
}
public void onAnimationStart(Animation arg0) {
}
});
}
}
Here’s the code for splash.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android = "http://schemas.android.com/apk/res/android"
android:orientation = "vertical"
android:layout_width = "match_parent"
android:layout_height = "match_parent"
android:background = "#000">
</LinearLayout>
Finally, here’s the xml for fading out:
<set android:shareInterpolator="false" xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:duration="500"
android:startOffset="2500">
</alpha>
</set>
A couple notes:
Right now the splash screen is just for show (meaning I’m aware that right now it’s not serving any real purpose).
I can paste the AndroidManifest xml or whatever else you think might be necessary.
Any and all help is appreciated. Thanks!
The animation ends, then it flips back to what it was previously. Android animation is confusing, but imagine what you’re seeing is a mirage. Nothing about the view you’re animating actually changes. Once its over, it goes right back to what it was.
As an example, create a button 100dp x 100dp, and animate is by scaling is small, or rotating. Very slowly. As its running, if you click on areas that look blank, the button will still register the hit. That’s because its still “there”, but you don’t see it.
What you need to do is set visibility on the image in the animation listener:
You may need to do it in onAnimationStart. Experiment.
I did a presentation on this a while back. May be useful:
https://docs.google.com/present/view?id=djqv5kb_187c62jvbf7