Navigation Styles in Android - android

It should be a pretty simple question that I cannot find through google or the docs for the life of me. How do I change the transition style of my activity?
From what I've heard, there are the grow, left/right and up/down transitions for presenting and dismissing activities, but I don't have a clue how to implement them.

WHen you are doing:
startActivity(intent);
just put:
startActivity(intent);
overridePendingTransition(animIn, animOut);
animIn and animOut are ints that you can just define in anim resources folder for example:
slideInLeft.xml:
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="100%p" android:toXDelta="0%p"
android:duration="#android:integer/config_longAnimTime" />
slideOutLeft.xml:
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="0" android:toXDelta="-100%p"
android:duration="#android:integer/config_longAnimTime" />
And when you want to return to the first activity you need to do the same but in finish method of activity:
finish();
overridePendingTransition(animIn, animOut);

You can use activity.overridePendingTransition. It takes an enter and exit animation resource ids.

Related

Stop image-view by using animation on particular screen position

This is what I have done now I want to stop this animation on a particular screen position and I know during the animation it could not stop so please provide another way where I could implement this functionality in my app.
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/linear_interpolator">
<translate
android:toYDelta="100%p"
android:duration="6000"
android:fillEnabled="false"
android:startOffset="5000"
android:fillAfter="false"/>
</set>
You have to give android:fromXDelta=""
android:toXDelta=""
android:fromYDelta=""
android:toYDelta=""

Animate the activity entry

I need to start an activity in an animated way..can anyone help me?
Creating an intent and starting an activity in normal way will show new activity.I need to start it from one side,say left side..how to animate it near creating intent..
Use the following:
this.overridePendingTransition(R.anim.slidein_left, R.anim.slideout_right);
Where R.anim.* are Animation XML files in your /res/anim/ folder.
The following is an example of my slidein_left:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="500"
android:fromXDelta="-100%"
android:toXDelta="0%" />
</set>
And slideout_right:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="500"
android:fromXDelta="0%"
android:toXDelta="100%" />
</set>
What this will do is slide both activities to the left, making the new activity slide in from the left, pushing the old activity out to the right.
Also, as stated by #njzk2, please attempt to make an effort yourself before asking questions, and provide us with things that you may have already tried.

View to leave from left and enter from right

I want to add animation so that my imageview slide towards the left,leave the screen and enter from the right ,sliding back to its original position. I tried doing something like this ..
<translate
android:duration="1000"
android:fromXDelta="0"
android:toXDelta="-100%p" />
<translate
android:startOffset="1000"
android:duration="1000"
android:fromXDelta="100%p"
android:toXDelta="0" />
But the animation is not as per my wish.. Can anyone help me out
Edit: Okay so what you are trying to do is a pain in the a** (ye another one of those android things that should have been simple)! Having two animations after each other just doesn't pan out too well on earlier versions of android. On never versions you can use animationset from api lvl 11. Example here. Alternatively I'd go with a simpler animation.
Here is how to do slide in/out for activity (old answer):
Slide in left activity:
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="100%p" android:toXDelta="0"
android:duration="#android:integer/config_shortAnimTime"/>
Slide in right activity:
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="-100%p" android:toXDelta="0"
android:duration="#android:integer/config_shortAnimTime"/>
Slide out left activity:
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="0" android:toXDelta="-100%p"
android:duration="#android:integer/config_shortAnimTime" />
Slide out right activity:
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="0" android:toXDelta="100%p"
android:duration="#android:integer/config_shortAnimTime" />
Example usage:
Intent intent = new Intent(this, YourNewActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_left);
Example usage on back:
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
super.onBackPressed();
overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_right);
}
return super.onKeyDown(keyCode, event);
}
As Warpzit said, its a bug and is a known issue... as in here
I wasted my time thinking it was a mistake from my side.An alternative specified by the developer is--
"You can achieve it by using two Animations. Start the first one and
when it ends (using an animation listener to be notified), start the
second one. It's not as nice and easy but it should work."
and another thing i learned is that android honeycomb has more animation features than the old versions..Inorder to use these features in pre-honeycomb versions we may use nineoldandroids

Android fade in , fade out animation issue

I'm trying to customize the animation between two activities by fading out the splashscreen and fading in the main activity.
I trying two solutions, one with fade_in.xml and fade_out.xml where controlling alphas (0-1 , 1-0) and calling everything with overridePendingTransaction(fade_in, fade_out) and one with fade and hold like ni api demo (api/app/animation/fade);
The main problem is that the splashscreen (first animation ) is losing its alpha while sliding to the right as well and the second activity is appearing as wanted.
How is possible to lock the splashscreen to its original position and just making it fading out?
fade
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/accelerate_interpolator"
android:fromAlpha="0.0" android:toAlpha="1.0"
android:duration="#android:integer/config_longAnimTime" />
hold
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/accelerate_interpolator"
android:fromXDelta="0" android:toXDelta="0"
android:duration="#android:integer/config_longAnimTime" />
overridePendingTransition(R.anim.fade, R.anim.hold);
You can use the callback for .fadeOut().

Animation between Activity with Android

i need to understand animation on Android.
For example, my application starts with an activity with a button in the bottom, when the user click on the button i want that another activity appears with an animation from bottom to top and i want that the button becomes the "header" of this second activity.
How can i achieve this?
Thank You
Daniele
Thank you to DecodeGnome for the answer! It works!
But i have some problem with the animation when i want to close this activity, i create a anim_out.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="0%p"
android:fromYDelta="0%p"
android:toXDelta="0"
android:toYDelta="100%p"
android:duration="300" />
</set>
but this doesn't work (the second parameter of overridePendingTransition what is used for?).
I try to call a new overridePendingTransition in onStop() function:
public void onStop(){
super.onStop();
overridePendingTransition(R.anim.top_to_bottom, R.anim.top_to_bottom);
}
But when i call finish to the second activity, i still see the default animation (from left to right)!
Thank you again to who'll help me.
1) Create a folder called anim in res folder
2) Add 2 new XML animations there (example, anim_in.xml & anim_out.xml)
3) put this line of code in the new activities onCreate:
overridePendingTransition(R.anim.anim_in, R.anim.anim_out);
Anim_in.xml example:
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="0%p"
android:fromYDelta="100%p"
android:toXDelta="0"
android:toYDelta="0%p"
android:duration="300" />
</set>
4) Place the button (header) in the top of the layout of the second activity.
Use this code:
public void onBackPressed() {
super.onBackPressed();
overridePendingTransition(R.anim.top_to_bottom, R.anim.top_to_bottom);
}

Categories

Resources