I have custom bottom menubar. I am trying to implement animation on view visible. my code is like below
Animation slideUp = AnimationUtils.loadAnimation(CardMainActivity.this, R.anim.slide_up);
ll_fonttextview.setAnimation(slideUp);
ll_fonttextview.setVisibility(View.VISIBLE);
and XML like this
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="500"
android:fromYDelta="100%"
android:toYDelta="0" />
</set>
Its working fine but after some click, its stop showing animation. I am not getting any error for that. Let me know if anyone have idea to fix it.
Thanks
Related
I have a generic FadeOut animation that is used on a lot of other things. I took out a button and switched it to a new button leaving the onClick the same. The only difference is position and src:Image. What I mean by not working is that it just goes to view gone and doesn't fadeout. it worked as intended with the other button but not this one
MainActivity
public void onPreferenceClose(View view){
FadeOut = AnimationUtils.loadAnimation(MainActivity.this, R.anim.fade_out);
FadeIn = AnimationUtils.loadAnimation(MainActivity.this, R.anim.fade_in);
if(preferences.getVisibility() == View.VISIBLE){
preferences.startAnimation(FadeOut);
preferences.setVisibility(View.GONE);
preferences.clearAnimation();
w_Toolbar.startAnimation(FadeIn);
w_Toolbar.setVisibility(View.VISIBLE);
p_Web.setClickable(false);
}
}
xml
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:fillBefore="true"
android:fillAfter="true"
android:duration="350">
<alpha
android:fromAlpha="1.0"
android:toAlpha="0.0"
/>
your Fadeout animation is working but as you are setting the visibility (preferences) to gone it doesnt show animation ..because it makes it Gone first.. dont use setVisibility to Gone it isnt required for fadeout anim.. it will automatically do that for you ...or you can use listeners for your animation and at the end of animation make the view Gone
`
<alpha
android:duration="1000"
android:fromAlpha="1.0"
android:interpolator="#android:anim/accelerate_interpolator"
android:toAlpha="0.0" />
`
use this code for anim..
done forget to use android:fillAfter="true" > in set ...
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true" >
remove this line.
preferences.clearAnimation();
your animation started and was cleared, that's why you cant see it
I am trying to switch from my "activity_main.xml" to a second .xml after a button click. I have already connected the button and put in setContentView(R.layout.view) and it works but I want it to animate. I want the view to come from the right and then the opposite when the user press back. I need a animation like a change of page in a book, I am doing this in eclipse if that helps.
I'm not sure how to get a "change of page in a book" animation, but here is how you would implement a slide in/slide out animation between activities which looks pretty good.
First, create two different XML files for the sliding animation. One for sliding in:
<?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>
...and one for sliding out:
<?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>
Now you can use these animations each time you press a button (or whatever your app does to move between activities) like so:
public void onClick(View v)
{
// set the animation to move once the button is clicked
overridePendingTransition(R.anim.slide_out, R.anim.slide_in);
Intent i = new Intent(MoveFromThisClass.this, MoveToThisCLass.class);
}
To move back to the previous class, just swap the slide_in and slide_out like this:
overridePendingTransition(R.anim.slide_in, R.anim.slide_out);
Hope this helps.
UPDATE (for the second part of your question):
"animation like a change of page in a book", i think you mean page curl annimation. if is that what you are looking for, you can use this library
I just want to create a fade out effect on a VideoView object.
The problem: Although I did set a certain duration for the animation, it looks like there's no duration. The VideoView object disappears immediately..
Things I've already tried:
AlphaAnimation anim = new AlphaAnimation(1, 0);
anim.setDuration(2000);
anim.setFillAfter(true);
mVideoView.setVisibility(View.VISIBLE);
mVideoView.startAnimation(anim);
the second try:
Animation anim = AnimationUtils.loadAnimation(this, R.anim.fadeout);
anim.setFillAfter(true);
mVideoView.startAnimation(anim);
in fadeout.xml:
<?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:duration="2000"
/>
</set>
I'd be glad if someone could help me here.
Ok, I'm not entirely sure VideoView supports this kind of animation.
I did a workaround by fading in a black ImageView object...yeah, it's not best solution.
But the effect is the same :D
Another way would be to create a screenshot, deactivate the VideoView and then to let the screenshot fade out.
i Am trying to slide a whole view from RIght to left and left to right.
Here is the code
Utilities.vibrate(v.getContext());
Animation animation = AnimationUtils.loadAnimation(v.getContext(), R.anim.leave);
mainView.startAnimation(animation);
This will make it move from left to right.
Here is leave.xml code
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate android:fromXDelta="-90%" android:toXDelta="0%"
android:fromYDelta="0%" android:toYDelta="0%"
android:duration="700"/>
</set>
It works fine however once the transition is done. It moves back to its original position. How can I make it stay at the slider position?
Add these lines after declaring your animation,
animation.setFillAfter(true);
animation.setFillEnabled(true);
I've taken some animation xml straight from the android docs, and as
far as I can see, doesn't work on either my 2.1 update 1 emulator or
my 2.1 update 1 Galaxy S device.
Specifically, I'm trying to create an animation to pulsate a view
(i.e. make it smaller then larger in one animation)
This is the very simple markup:
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:fromXScale="1.0"
android:toXScale="0.5"
android:fromYScale="1.0"
android:toYScale="0.5"
android:pivotX="50%"
android:pivotY="50%"
android:duration="1000" />
<set android:startOffset="1000">
<scale
android:fromXScale="0.5"
android:toXScale="1.0"
android:fromYScale="0.5"
android:toYScale="1.0"
android:pivotX="50%"
android:pivotY="50%"
android:duration="1000" />
</set>
</set>
So what I'm trying to achieve is to reduce the view from its size to
half of it over a second, then to increase it back to its original
size over a second. So to re-iterate, over two seconds it should go from original -> half size -> original.
What actually happens is it snaps instantly to half of the views size
(even though fromX/YScale is at 1.0) and then performs the animation over two seconds
and snaps back to original size afterwards.
Can anyone else try this out quickly? If others see this behaviour
I'll submit it as a bug. I just can't believe something so basic could
be broken!?
Also, copying this animation under the "Tween Animation" heading on
this page http://developer.android.com/guide/topics/graphics/2d-graphics.html
word for word also doesn't animate as per the page says. Seems to be broken in exactly the same way!
Anyone got any ideas?
Thanks!
Andy.
Something that I've recently discovered and is partially responsible for the undesired behavior of your animation is the fact that many XML attributes used in the <set> tag do not work!
In your code example you have <set android:startOffset="1000">
Because of a ridiculous bug/defect, Android will ignore this attribute which will cause your second child <set> of animations to start concurrently with your parent <set>
What makes this even more frustrating is that this attribute works programatically in code, setStartOffset() but not in XML.
I spent a few frustrating hours figuring out which attributes work in code and XML for AnimationSets and submitted a bug report/issue here: Issue 17662
In summary:
setRepeatCount() / android:repeatCount
This attribute (as well as repeatMode) does not work in code or XML. This makes repeating an entire set of animations difficult.
setDuration() / android:duration
Setting this on an AnimationSet in code WORKS (overrides all durations of children animations), but not when included in the tag in XML
setFillAfter() / android:fillAfter
This works in both code and XML for the tag. Strangely I have gotten it to also work without the need to set fillEnabled to true.
setFillBefore() / android:fillBefore
Seems to have no effect/ignored in both code and XML
setFillEnabled() / android:fillEnabled
Seems to have no effect/ignored in both code and XML. I can still get fillAfter to work even without including fillEnabled or setting fillEnabled to false.
setStartOffset() / android:startOffset
This works only in code and not XML.
Needless to say this causes a lot of unnecessary frustration.
I removed the second <set> tag, so there's only one <set> with two <scale> children. This got one cycle working ok but it failed to repeat. Maybe you have to listen for the animation ending and manually restart it (so the offsets start from 0 each time).
On the bright side I was able to use repeatMode to achieve the effect you seem to want, using just one tag:
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:repeatMode="reverse"
android:fromXScale="1.0"
android:toXScale="0.5"
android:fromYScale="1.0"
android:toYScale="0.5"
android:pivotX="50%"
android:pivotY="50%"
android:duration="1000" />
Try the following codes. What's missing is repeatMode = "-1" in previous answer. Then you'll see the image pulsating indefinitely without using listener.
In res/anim/pulsate.xml:
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" >
<scale
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromXScale="0.5"
android:fromYScale="0.5"
android:pivotX="50%"
android:pivotY="50%"
android:repeatMode="reverse"
android:repeatCount="-1"
android:toXScale="1.0"
android:toYScale="1.0" />
In java file:
Animation animPulsate = AnimationUtils.loadAnimation(JoinRecipeClubActivity.this, R.anim.pulsate);
ImageView ivFinger = (ImageView) findViewById(R.id.wivFinger);
ivFinger.startAnimation(animPulsate);