I've seen in applications like facebook, that intent to call a do a screen effect that goes from the bottom up, or left to right or top to bottom ...
I searched and I could not find as anyone knows how this can be done?
Here is an example:
Intent intent = new Intent(this, ItemPage.class);
startActivity(intent);
overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_left);
slide in left xml:
<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 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_shortAnimTime" />
Related
Is there a way to use the default startActivity() and onBackPressed() animations from a specific Android version?
Different versions of Android have slightly different default animations and I would like to keep it consistent across all versions.
For example API 31's default startActivity() animation pops the activity from the center of the screen and onBackPressed() slides it down and disappears. Where as in API 33 the default startActivity() animation slides in from right-to-left and onBackPressed() slides out from left-to-right.
Try This
Starting from API level 5 you can call overridePendingTransition immediately to specify an explicit transition animation
startActivity();
overridePendingTransition(R.anim.fadein, R.anim.fadeout);
res/anim/fade_in.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<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="500" />
</set>
res/anim/fade_out.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/anticipate_interpolator"
android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="500" />
</set>
I have a floating action button that, when pressed, starts a new activity.
Is there a way to animate it like on Google's Material design guidelines? I'm talking about something like this (from here).
As i have created a file in anim folder
right_bottom_up.xml
<?xml version="1.0" encoding="utf-8"?>
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="#integer/time_fade"
android:fromXDelta="100%p"
android:fromYDelta="100%p"
android:toYDelta="0%p"
android:toXDelta="0%">
</translate>
no_animation.xml
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="#android:integer/config_longAnimTime"
></translate>
slide_down_back.xml
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="#integer/time_fade"
android:fromYDelta="0%p"
android:toYDelta="100%p"></translate>
In activity
start your activity after intent calling:
overridePendingTransition(R.anim.right_bottom_up, R.anim.no_animation);
in your second activity onBackPress() write this line
overridePendingTransition(R.anim.no_animation, R.anim.slide_down_back);
Refer Below lib project , its same as you share video in this question.
https://github.com/gowong/material-sheet-fab
May be this definitely helps you.
I'm attempting to create an android activity transition where activity a calls activity b, I need activity b to slide in from the right of the screen when called and slide out of the right side of the screen when destroyed, during both transitions I need activity a to stay in place and not animate whatsoever.
I've searched for this and all animations I find are making activity a animate as well as I am trying to avoid this, any help will go a long way thanks!
intent from calling activity:
public void searchButtonClick(View view) {
Intent intent = new Intent(this, SearchActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.animate1, R.anim.animate2);
}
animate1.xml
<?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="#android:integer/config_mediumAnimTime" />
</set>
animate2.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:fromXDelta="0%" android:toXDelta="100%"
android:fromYDelta="0%" android:toYDelta="0%"
android:duration="700" />
</set>
Add below line
overridePendingTransition(R.anim.animate1, R.anim.animate2);
in your onStart() or onCreate() of SearchActivity.class
I'm having trouble figuring out how to slide activities in and out with a push of a button. What I want is for the user to push a button and then the screen slides. The way I want it is for the 1st activity (the one with the button) to slide out to the left while the new 2nd activity slides in from the right.
With the below code, when the button is clicked, the 1st activity slides out to the right when I want it to slide out to the left. Then when it is done sliding, all that is remaining is a black screen for a split second and then the 2nd activity just appears and does not slide in.
So the 1st activity is sliding out the incorrect direction and the next activity just appears instead of sliding. What am I doing wrong? I am having a hard time understanding the XML files so hear is the code for everything below.
1st activity
#Override
public void onCreate(Bundle savedInstanceState) {
playBtn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(MainMenu.this, Levels.class);
startActivity(intent);
overridePendingTransition(R.anim.enter_from_right, R.anim.exit_out_left);
}
});
2nd activity
#Override
public void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.levels);
overridePendingTransition(R.anim.enter_from_left, R.anim.exit_out_right);
So I am thinking that some of my XML files might be incorrect. Here they are.
enter_from_left.xml
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="600"
android:fromXDelta="100%"
android:toXDelta="0%" >
</translate>
</set>
enter_from_right.xml
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="600"
android:fromXDelta="-100%"
android:toXDelta="0%" >
</translate>
</set>
exit_out_left.xml
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="600"
android:fromXDelta="0%"
android:toXDelta="-100%" >
</translate>
</set>
exit_out_right.xml
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="600"
android:fromXDelta="0%"
android:toXDelta="100%" >
</translate>
</set>
EDIT
Removing the overridePendingTransition() from the 2nd activity made it so the 1st activity slides out to the left which is what I wanted. But, when the 1st activity slides away, it still is just revealing a black screen instead of having the 2nd activity slide in from the right.
Instead of overriding the animation in both startActivity() and the new activities onCreate(), you only need to override the animation just after the startActivity() call.
The two ints you provide for overridePendingTransition(int enterAnim, int exitAnim) correspond to the two animations - removing the old Activity and adding the new one.
For your second question, I believe you have the fromXDelta set wrong, -100% should be all the way off the left-hand side of the screen, not the right, so changing this to 100% should fix it.
look at my gist, it works perfectly:
1.Override CommonActivity's startActivity and finish
#Override
public void startActivity(Intent intent) {
super.startActivity(intent);
overridePendingTransition(R.anim.from_right_in, R.anim.from_left_out);
}
#Override
public void finish() {
super.finish();
overridePendingTransition(R.anim.from_left_in, R.anim.from_right_out);
}
2.from_left_in.xml
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="-100%p"
android:toXDelta="0"
android:duration="300"/>
<alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="300" />
</set>
3.from_right_in.xml
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="100%p"
android:toXDelta="0" android:interpolator="#android:interpolator/accelerate_decelerate"
android:duration="300"/>
<alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="300" />
</set>
4.from_left_out.xml
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="0"
android:toXDelta="-100%p"
android:duration="300"/>
<alpha android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="300" />
</set>
5.from_right_out.xml
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="0"
android:toXDelta="100%p"
android:duration="300"/>
<alpha android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="300" />
</set>
gist link: https://gist.github.com/JagieChen/f5cc44bf663f3722bd19097be47ccf9b
There's an error not only in the enter_from_right animation, that should have a fromXDelta of 100% instead of -100%, but even in the enter_from_left animation, that should fave a fromXDelta of -100% instead of 100%.
Cheers,
Change fromXDelta to -100% from enter_from_left and fromXDelta to 100% from enter_from_right in your code, this will give you a correct sliding animation.
Don't forget the pivot at this point!
fE. Move from up to down. pivotY is 100% that meen's bottom, so your 0% are on the bottom and -100% are up and you don't see it. Makes it more handy when you set the pivot to your border.
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true"
android:shareInterpolator="false">
<translate
android:duration="800"
android:fromYDelta="-100%"
android:toYDelta="0%"
android:interpolator="#android:anim/bounce_interpolator"
android:pivotX="50%"
android:pivotY="100%"/>
</set>
When the user changes the language locale, I would like to reload the activity with the new locale. I want to create an animated transition when finishing the Activity and starting it again.
The transition animation is as follows:
The exit animation is to scale the activity to the center of the screen.
The enter animation is to scale the activity from the center of the screen.
finish();
overridePendingTransition(0, R.anim.scale_to_center);
Intent intent =new Intent(SettingsActivity.this, SettingsActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.scale_from_center, 0);
and my scale_to_center.xml is:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale android:fromYScale="1.0" android:toYScale="0"
android:fromXScale="1.0" android:toXScale="0"
android:pivotX="50%" android:pivotY="50%"
android:duration="500"/>
</set>
and my scale_from_center.xml is:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale android:fromYScale="0" android:toYScale="1.0"
android:fromXScale="0" android:toXScale="1.0"
android:pivotX="50%" android:pivotY="50%"
android:startOffset="500"
android:duration="2000"/>
</set>
The problem is that ONLY the enter transition appears and the exit transition do not appear. I tried to add a delay to the exit transition but it didn't work either.
However when I changed the code to only animate the exit of application. It worked.
finish();
overridePendingTransition(0, R.anim.scale_to_center);
Thanks.
Set the two animations on the method overridePendingTransition and call finish after you've called startActivity:
Intent intent = new Intent(SettingsActivity.this, SettingsActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.scale_from_center, R.anim.scale_to_center);
finish();
It doesn't work here as well. I fixed it creating a null_animation.xml:
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="#android:integer/config_mediumAnimTime"
android:fromYDelta="0%p"
android:toYDelta="0%p" />