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.
Related
In my application I want to animate my activity from right to left. Till now I am try this :
startActivity(intent);
finish();
overridePendingTransition(R.anim.slide_in_right,R.anim.slide_out_left);
and this working fine but my previous activity got finished. What I want to do the same animation without finishing previous activity.
while trying like this :
startActivity(intent);
overridePendingTransition(R.anim.slide_in_right,R.anim.slide_out_left);
only newly started activity go into animation and previous activity does get any effect. How can I animate both activity without finishing the previous one?
You should use Handler in this case!
Put time on Handler on First Activity. During this time animate your first activity. After this step handler give the control to your second activity and then you start animation on second activity
I think that your animations might be the problem. I have the same effect using the following animation files:
slide_in_right.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:duration="#android:integer/config_mediumAnimTime"
android:fromXDelta="100%"
android:fromYDelta="0%"
android:toXDelta="0%"
android:toYDelta="0%" />
</set>
slide_out_left.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:duration="#android:integer/config_mediumAnimTime"
android:fromXDelta="0%"
android:fromYDelta="0%"
android:toXDelta="-100%"
android:toYDelta="0%" />
</set>
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=""
I have two activities and I want that when the user touches a button on the first activity, the new activity slides in from the left and moves to the right while the first activity does the same, it moves to the right and slides out, so it would give an effect in which the new activity pushes the old one to the right and replaces it.
In order to do that, I have written the following XMLs:
In animation
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="-100%"
android:toXDelta="0"
android:duration="1250" />
</set>
Out animation
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="0"
android:toXDelta="-100%"
android:duration="1250" />
</set>
I call the overridePendingTransition(R.anim.anim_in,R.anim.anim_out); function in the onCreate method of the new activity. In the resulting effect, the new activity moves from the left to right correctly, but the first, older activity moves into the opposite direction; it moves to the left. I want to revert the moving direction of this first activity. How can I do that, is there a XML property which serves to this purpose?
Change
android:toXDelta="-100%"
to
android:toXDelta="100%"
in the out animation.
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.
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().