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.
Related
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>
http://framerjs.com/examples/preview/#carousel-onboarding.framer like this i have to develop,please check this link only on Chrome .
What I'd do is an Animation Resource File (a file in the res>anim directory of your project. If you don't have the anim directory you can simply create it.).
The content of this file (named as you wish, like myanimation.xml) should be:
<?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" />
<translate
android:fromXDelta="0"
android:toXDelta="0"
android:fromYDelta="0"
android:toYDelta="-50" />
</set>
The tag means that the object will animate from completely opaque (1.0) to completly trasparent (0.0)
The tag means that the object will animate from its starting position to the same X coordinate and 50 pixels above.
To use this animation from an Activity simply use:
Animation myAnimation = AnimationUtils.loadAnimation(this, R.anim.myanimation);
myAnimation.setDuration(millisecYouWant);
viewIWantToAnimate.startAnimation(myAnimation);
for more complex animations look at this link: http://developer.android.com/guide/topics/resources/animation-resource.html
EDIT: I think the question should have more details, in this case something like the piece of code where you want to applicate this animation, or what you want to animate (like an ImageView, or a Layout ...)
First of all I'm working with the Android-L preview. Now, For anyone to not to misunderstand what navigation bar is, here's a pic of it:
https://imageshack.com/i/f0bjjDnQp
I'm applying the activity animation that follows:
activity.startActivity(intent);
activity.overridePendingTransition(R.anim.slide_in_from_bottom, R.anim.scale_in);
Where R.anim.slide_in_from_bottom.xml is:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="300"
android:fromYDelta="100%"
android:toYDelta="0%"/>
</set>
and R.anim.scale_in is:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:duration="300"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="0.9"
android:toYScale="0.9"/>
<alpha
android:duration="300"
android:fromAlpha="1.0"
android:interpolator="#android:anim/accelerate_interpolator"
android:toAlpha="0.1"/>
</set>
The animation works fine except for the fact that the new activity does the animation on top of the navigation bar, I'd like it to be the opposite. Also I can see the black status bar during the whole animation which I would like to avoid too.
UPDATE:
So I found what the problem is. With the introduction of Android L preview we have the option to set this Material theme, and that theme makes the animations between activities this way. If I set android:Theme.Holo.Light for instance, everything works fine. As soon as I add this Material theme I got this ugly effect of overlaying the Navigation Bar.
So I thought I could try to find the right parameter in the Material Theme to make it behave as the old theme but I can't manage to figure it out. I've tried setting this line below, but it doesn't work either.
<item name="android:windowActionBarOverlay" >false</item>
I have an ImageView element that I create in my code and place inside of my RelativeLayout. I set this image to be Invisible to start off with using the following code:
arrow.setVisibility(View.INVISIBLE);
I then defined a Fade-In Alpha animation via XML:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false"
android:fillEnabled="true"
android:fillAfter="true"
android:fillBefore="true">
<alpha
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:startOffset="100"
android:duration="300" />
/set>
To run the animation:
I simply call the following to start the animation
myview.startAnimation(myanimation);
The issue I am seeing is that my animation causes the ImageView to flicker in at full visibility and then go through the animation of alpha 0 to 1. How do I fix this? I can't set the initial alpha value to 0 because the alpha animation is based on percentage and not absolute alpha value. (ex: 0*current value to 1*current value)
Any help would be greatly appreciated.
I think the problem is, with this line of code:
android:fillBefore="true"
Here, Try this code instead, it works for me :
<?xml version="1.0" encoding="UTF-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="2000"
android:fillAfter="true"
android:fromAlpha="0.0"
android:toAlpha="1.0" />
If you are using animateLayoutChanges in your layout file in combination with the animation, toggling the View visibility will result in two animations running and the view flashing or blinking. Setting view visibility causes the layouts animateLayoutChanges to run and to fade the view in once and then the animation you created causes a second animation to run as well.
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.