I can't manage to get the fillAfter property of an animation to work.
I used it both in the translate and the set of the animation in xml but it always jumps to the standard dialog position at the end. Is this even possible?
Current slide in animation in xml:
<set
android:fillAfter="true"
xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="100%"
android:toXDelta="70%"
android:fromYDelta="100%"
android:toYDelta="70%"
android:duration="2000" />
</set>
The Themes.xml that is being applied to the dialogs:
<style name="theme_dialog" parent="#android:style/Theme.Dialog">
<item name="android:windowAnimationStyle">#style/style_slide_in_dialog</item>
</style>
<style name="style_slide_in_dialog">
<item name="android:windowEnterAnimation">#anim/animation_slide_in_dialog</item>
<item name="android:windowExitAnimation">#anim/animation_slide_out_dialog</item>
</style>
Animations like TranslateAnimation are temporary. If you want the effect to persist when the animation is complete, you need to register an AnimationListener and do something to make the change permanent in onAnimationEnd(). For example, with a TranslateAnimation, you would need to adjust your LayoutParams to have it reside in your final position.
Related
first of all I am using API 28 (Android 9.0)
I want my second activity to appear from left to right when I click the menu button on mainActivity.
I have overrided the pending transition in main activity like below:
startActivity(myintent);
this.overridePendingTransition(R.anim.left_to_right, R.anim.no_move);
the left_to_right.xml with duration 100ms(that doesnt seems to be 100ms, its almost 1 second, but animation works fine):
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="100"
android:fromYDelta="0%"
android:fromXDelta="-100%"
android:toXDelta="0%"
android:toYDelta="0%">
</translate>
</set>
and no_move.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromYDelta="0%"
android:toYDelta="0%"
android:fromXDelta="0%"
android:toXDelta="0%">
</translate>
</set>
this is my theme.xml:
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.Chess" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Primary brand color. -->
<item name="android:windowActivityTransitions">true</item>
<item name="colorPrimary">#color/purple_500</item>
<item name="colorPrimaryVariant">#color/purple_700</item>
<item name="colorOnPrimary">#color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">#color/teal_200</item>
<item name="colorSecondaryVariant">#color/teal_700</item>
<item name="colorOnSecondary">#color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
</resources>
the activity starts how I want(animation) but the only problem is its duration.it takes like 1 second for compelete translate.
there is no extra code to mention here, all i add was that 2 anim file and overriding pendingTranstition
plus setting windowActivityTranstition to True in themes.xml
WHAT I WANT TO DO...
the animation I want here is like when you click the menu button(on the top and left) in Telegram app, the menu shows up smoothly, I want something beautifule like that.
so if there is a better way to do such things or if telegram uses another way for this beautiful animation please let me know.thanks in advance.
Use one activity with DrawerLayout view for that left menu. It has open/close functions, fade effect etc. Telegram app uses their own custom view for that menu here it is. You can also check source code of their activity here (check DrawerLayoutAdapter, DrawerLayoutAdapter variables)
I am finishing FlashScreen and starting MainActivity using startActivity();
and I want to slide linearLayout of MainActivity from left to right slowly like an animation. But it's not happening. At first the linearLayout loads up and then it performs the animation so it's of no use.
Here's my code :
slide_from_left.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate android:fromXDelta="-100%" android:toXDelta="0%"
android:fromYDelta="0%" android:toYDelta="0%"
android:duration="700"/>
</set>
MainAcitivity.java
Animation animFadein = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.slide_from_left);
mLinearLayoutParent.startAnimation(animFadein);
Please help me with this.
Thanks
if you are sliding from any side, then this View should be "slided out" in this direction when initialised (on start). consider adding proper param to XML, in your case it would be android:translationX for mLinearLayoutParent. use some very high value to be shure that this View isn't visible, as in here you can't set translation by % of view like in <translate tag. when anim starts then android:fromXDelta="-100%" line will move View to this position (exact -100% of width, as initial for animation) at very beginning of animation
To animate every activity when it opens or closes, you need to create four animation files (namely : slide_in_right, slide_in_left, slide_out_right, slide_out_left). After creating these animations, you will have to add the following code in your values/styles.xml:
<style name="android:customActivityAnimation" parent="#android:style/Animation.Activity">
<item name="activityOpenEnterAnimation">#anim/slide_in_right</item>
<item name="activityOpenExitAnimation">#anim/slide_out_left</item>
<item name="activityCloseEnterAnimation">#anim/slide_in_left</item>
<item name="activityCloseExitAnimation">#anim/slide_out_right</item>
</style>
After that in your default application theme add this style :
<style name="android:windowAnimationStyle">#style/customActivityAnimation</style>
I built an application with quite a few activities and I would like to have "slide from right on enter/slide from left on exit" transitions between them.
I read more than once that slide transitions should be the Android default, but on the device I am developing on the transitions are fade in/fade out by default (Galaxy Tab 2 7", on ICS 4.0).
Is there anything I need to declare at application level, for example in the manifest file?
I am asking because otherwise I would need to add overridePendingTransition (R.anim.right_slide_in, R.anim.left_slide_out); to all my transitions which are plenty...just wondering if I am missing something before going that road.
Many thanks
No answers...on the devices 4+ I tried, the animation is a fade-in fade-out with zoom in or out...
I added the code manually where I wanted to have the slide animation:
//open activity
startActivity(new Intent(this, MyActivity.class));
overridePendingTransition(R.anim.right_slide_in, R.anim.left_slide_out);
xml animation right to left:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/accelerate_decelerate_interpolator" >
<translate
android:duration="300"
android:fromXDelta="100%p"
android:toXDelta="0" />
</set>
xml animation left to right:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/accelerate_decelerate_interpolator" >
<translate
android:duration="300"
android:fromXDelta="0"
android:toXDelta="-100%p" />
</set>
In your style.xml file put
<style name="WindowAnimationTransition">
<item name="android:windowEnterAnimation">#android:anim/slide_in_left</item>
<item name="android:windowExitAnimation">#android:anim/slide_out_right</item>
</style>
and add
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
...
<item name="android:windowAnimationStyle">#style/WindowAnimationTransition</item>
</style>
There is a way which involves creating a style and then adding it in manifest here:
How to change all the activity transitions at once in Android application?,
yet I only managed to make it work over startActivity(). Whenever back is pressed this method won't work or I might just missing something.
I has a nice PopupWindow which I want to appear with an animation. I do it like this:
popup.setAnimationStyle(R.anim.appear);
popup.showAtLocation(popupMenuLayout, gravity, offsetX, offsetY);
I then set up a listener for changing the animation:
popup.setOnDismissListener(new PopupWindow.OnDismissListener(){
#Override
public void onDismiss(){
popup.setAnimationStyle(R.anim.disappear);
}
});
But, hey, it won't work. Neither for res/anim/appear:
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromYDelta="100%"
android:toYDelta="0"
android:duration="1000"
/>
Nor for res/anim/disappear:
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromYDelta="0"
android:toYDelta="100%"
android:duration="1000"
/>
Any clues?
Actually, PopupWindow.setAnimationStyle expects a style with 2 entries. You'll need to have two xmls, each containing a <set>, one for showing and the other for hiding the window. When this is done, put the following piece into values/styles.xml:
<style name="AnimationPopup">
<item name="android:windowEnterAnimation">#anim/popup_show</item>
<item name="android:windowExitAnimation">#anim/popup_hide</item>
</style>
and set your animation style to R.style.AnimationPopup. That'll do.
I've got this information from https://github.com/lorensiuswlt/NewQuickAction3D the documentation didn't seem to mention it.
Update:
An update to Android SDK in 2012 have changed XML syntax. The original #android:windowEnterAnimation now became android:windowEnterAnimation. So this answer is updated accordingly.
I have a widget which starts an activity when it is clicked. I'd like to have some kind of fancy animation to display this activity, rather than the standard scroll-from-right of Android. I'm having problems setting it, though. This is what I have:
slide_top_to_bottom.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="#android:anim/accelerate_interpolator">
<translate android:fromYDelta="-100%" android:toXDelta="0" android:duration="100" />
<alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="50" />
</set>
...which is referenced in anim.xml
<?xml version="1.0" encoding="utf-8"?>
<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
android:delay="50%"
android:animation="#anim/slide_top_to_bottom" />
But then where do I reference it from? I've tried both the base element of the activity I want to slide in, and the activitiy's entry in the manifest, both times with
android:layoutAnimation="#+anim/anim"
I might be doing this all wrong. Any help is much appreciated!
You can create a custom Theme with a reference to your own animation and apply it to your Activity in your manifest file.
I was successful in applying a custom animation for a floating window using the following style definition. You might be able to do something similar if you set the parent of your style to be "#android:style/Animation.Activity"
Look at the following files for further details on what you can override.
https://github.com/android/platform_frameworks_base/blob/master/core/res/res/values/styles.xml
https://github.com/android/platform_frameworks_base/blob/master/core/res/res/values/themes.xml
Here's my a portion of my styles.xml and manifest.xml
styles.xml
<style name="MyTheme" parent="#android:style/Theme.Panel">
<item name="android:windowNoTitle">true</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:windowAnimationStyle">#style/MyAnimation.Window</item>
</style>
<!-- Animations -->
<style name="MyAnimation" />
<!-- Animations for a non-full-screen window or activity. -->
<style name="MyAnimation.Window" parent="#android:style/Animation.Dialog">
<item name="android:windowEnterAnimation">#anim/grow_from_middle</item>
<item name="android:windowExitAnimation">#anim/shrink_to_middle</item>
</style>
Manifest.xml
<activity
android:name="com.me.activity.MyActivity"
android:label="#string/display_name"
android:theme="#style/MyTheme">
</activity>
startActivity(intent);
overridePendingTransition(R.anim.slide_top_to_bottom, R.anim.hold);
Check this link: overridePendingTransition method
Edit:
To Achieve the Animation for the Views. You have use the startAnimation Method like below
view.startAnimation(AnimationUtils.loadAnimation(
WidgetActivity.this,R.anim.slide_top_to_bottom));
Check this link:
It doesn't matter that your starting from a widget, wrote a tutorial so that you can animate your activity's in and out. This animation is set within the activity that your bringing into focus so you can do it with pendingIntent as well.
Enjoy:
http://blog.blundellapps.co.uk/animate-an-activity/