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>
Related
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.
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.
I wrote a code that uses setAnimationStyle in a popup window, when i check the code on a Galaxy 1 device running Android 2.2 OS everything worked great. But when i try it on the Galaxy 2 device running Android 2.3.5 OS the animation doen't work any more.
here is the code .
Thanks.
this is animation definition in style.xml
<style name="AnimationPopup" parent="android:Animation">
<item name="#android:windowEnterAnimation">#anim/popup_menu</item>
<item name="#android:windowExitAnimation">#anim/fadeout</item>
</style>
this is the animation located at res/anim
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromYDelta="100%"
android:toYDelta="0"
android:duration="300"
/>
<?xml version="1.0" encoding="UTF-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha android:fromAlpha="1.0" android:toAlpha="0.0" android:interpolator="#android:anim/accelerate_interpolator"
android:duration="500"/>
</set>
this is the code i use in the activity :
_menu = new PopupWindow(googlePopupInflator);
_menu.setOutsideTouchable(true);
_menu.setAnimationStyle(R.style.AnimationPopup);
_menu.showAtLocation(getWindow().getDecorView(), Gravity.BOTTOM, 0, 0);
I encountered same problem on moving to 2.3.4
Made a workaround: Animate the controls inside the PopupWindow.
My PopupWindow contained a main linear layou and inside it child linera layouts.
I tried to animate the main linear layout - didn't succeed.
Then I tried animating the child layouts and succeeded. Applied to each one of them a translate animation (a different instance of the animation to each one) and I animated them right after showing the PopupWindow. They all slide in them same time - net effect - as if the PopupWindow was animated by itself.
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've got a layout much like the one below. Currently when the back button is pressed the red linear layout's visibility is set to gone. However, I'd like it to "slide" up off of the page instead. How would I do this?
You need to use animations. here is the top in/out animations:
In Top
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromYDelta="-100%" android:toYDelta="0%" android:duration="300"/>
</set>
Out Top
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromYDelta="0%" android:toYDelta="-100%" android:duration="600"/>
</set>
Then in your activity get the view and apply an animation to it like this:
This are type Animation.
mSlideInTop = AnimationUtils.loadAnimation(this, R.anim.slide_in_top);
mSlideOutTop = AnimationUtils.loadAnimation(this, R.anim.slide_out_top);
and call them with this code:
header.startAnimation(mSlideOutTop);
header.setVisibility(View.INVISIBLE);
Here header is a LinearLayout wrapping my views. same thing if you want to make it slide in. just add the slide in animation and make the view visible.