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.
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>
Why I am not able to slide text view in android from right to left continuously?
I am using below xml:
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/linear_interpolator"
android:fillAfter="true">
<translate
android:fromXDelta="-3%p"
android:toXDelta="3%p"
android:duration="1200" />
</set>
If you want your animation to play continuously, you need to add the following two attributes to "translate" tag.
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/linear_interpolator"
android:fillAfter="true">
<translate
android:fromXDelta="-3%p"
android:toXDelta="3%p"
android:duration="1200"
android:repeatCount="infinite"
android:repeatMode="reverse"/>
</set>
Note that if “repeatCount" and "repeatMode" are added to "set" tag, things will not work as expected.
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 have some questions to the animations on android:
first of all, does someone have good links to sites where animations for android get explained? Only XML-Animations please, i dont want to use java-code for the animations..
The second question: I want to simply animate the activity from tight to left when it comes up and from left to right when it goes, but i can't achieve this simple animation.
My XML Files look like this:
push left in:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="#android:integer/config_shortAnimTime"
android:fromXDelta="-100%p"
android:toXDelta="0" />
<alpha
android:duration="#android:integer/config_shortAnimTime"
android:fromAlpha="1.0"
android:toAlpha="1.0" />
</set>
push right out:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="#android:integer/config_shortAnimTime"
android:fromXDelta="0"
android:toXDelta="100%p" />
<alpha
android:duration="#android:integer/config_shortAnimTime"
android:fromAlpha="1.0"
android:toAlpha="1.0" />
</set>
In my code i use: overridePendingTransition(R.anim.push_left_in,R.anim.push_right_out); and overridePendingTransition(R.anim.push_right_out,R.anim.push_left_in); after the super.finiah();
This is how I set up a simple fade in, fade out animation
Here's my incoming.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/decelerate_interpolator" >
<alpha
android:duration="#android:integer/config_mediumAnimTime"
android:fromAlpha="1.0"
android:interpolator="#android:anim/accelerate_interpolator"
android:toAlpha="0.0" />
Here's my outgoing.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/decelerate_interpolator" >
<alpha
android:duration="#android:integer/config_mediumAnimTime"
android:fromAlpha="0.0"
android:interpolator="#android:anim/accelerate_interpolator"
android:toAlpha="1.0" />
And here's how I call set the animation in my activity
Intent i = new Intent(this, ABCActivity.class);
startActivity(i);
ModeSelectActivity.this.overridePendingTransition(
R.anim.outgoing, R.anim.incoming);
Also, be sure to override onBackPressed() for the reverse animation
#Override
public void onBackPressed() {
// TODO Auto-generated method stub
super.onBackPressed();
ModeSelectActivity.this.overridePendingTransition(R.anim.outgoing,
R.anim.incoming);
}
You have many animations on this page:
http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/2.3.5_r1/frameworks/base/core/res/res/anim/
You can look at slide_in_left.xml,slide_in_right.xml, slide_out_left.xml and slide_out_right.xml.
You can use these transitions with overridePendingTransition().
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" />