Reputation: 2333
I've been recently getting my feet wet with android development.
What I would like to do, is once the app is opened; a screen with a logo would appear, hold for a second, then animate left to another screen.
I have layouts designed. How would I go about animating those 2? The java part is where I don't quite know where to begin.
Thanks in advance!
Upvotes: 0
Views: 208
Reputation: 2333
For those curious and are wanting to the same - having a splash page come up hang for a few seconds, then slide to an activity.
This is how I went with implementing the code. I found this from other users so I can't take credit for it, but thought it would be nice for people who might potentially stumble upon this.
public class logoSplash extends Activity {
private static final int SPLASH_DISPLAY_TIME = 2000; // splash screen delay time
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.logo);
new Handler().postDelayed(new Runnable() {
public void run() {
Intent intent = new Intent();
intent.setClass(logoSplash.this, fieldsActivity.class);
logoSplash.this.startActivity(intent);
logoSplash.this.finish();
// transition from splash to main menu
overridePendingTransition(R.anim.right_slide_in, R.anim.right_slide_out);
}
}, SPLASH_DISPLAY_TIME);
}
}
Upvotes: 2
Reputation: 771
When you launch the intent use overridePendingTransition(android.R.anim.slide_out_right, android.R.anim.slide_in_left);
if this isn't the effect you are after you can change the animations to other ones in android.R.anim
or define your own in XML and instead point to your anim folder R.anim
here is an example of a custom animation, you would save this in res/anim/
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="0" android:toXDelta="-50%p"
android:duration="@android:integer/config_shortAnimTime"/>
<alpha android:fromAlpha="1.0" android:toAlpha="0.0"
android:duration="@android:integer/config_shortAnimTime" />
</set>
Upvotes: 0