So I'm developing an Android App, it's a very simple app right now just 2 views which are switch using a ViewSwitcher. On each page there is a button to switch the views. For whatever reason the using the ViewSwitcher with an transition (smooth panning animation) on the start of the app the buttons don't correctly fire off their button pressed events.
For whatever reason they queue them up until the activity goes through a onPause / onResume cycle then they will fire all their queued events. This only happens if there is an attached animation with the ViewSwitcher. If i don't set any animation and the view switches instantly this doesn't happen. It looks like to be some sort of low level bug with the animation blocking forever on first startup.
This is how i create the animation :
Animation inFromRight = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, +1.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f);
inFromRight.setDuration(animDuration);
inFromRight.setInterpolator(new AccelerateInterpolator());
Taken off a sample from the net. Any ideas how to fix this? I rather not have the user exit and re-enter the app to get working buttons.
Thanks!
Related
This only seems to occur on Samsung devices (tested on S7 and Tab S2).
Problem
If any animation is playing, all dialog ripple and reveal affects are stunted, stop half way, or do not play at all.
For example, this imageview animation has been started:
RotateAnimation anim = new RotateAnimation(0.0f, 360.0f, Animation.RELATIVE_TO_SELF, 0.48f, Animation.RELATIVE_TO_SELF, 0.5f);
anim.setInterpolator(new LinearInterpolator());
anim.setRepeatCount(Animation.INFINITE);
anim.setDuration(2000);
ivStatus.startAnimation(anim);
Then I touch a button in a dialog or start a reveal animation.
The animation either freezes at random points or stutters horribly.
In my code, some reveals are dialogs so it blocks the user from doing anything when the dialog reveal stops half way.
Edit: This also occurs when using a progressView such as com.github.rahatarmanahmed.cpv.CircularProgressView, which animates.
How can this be prevented/fixed? This works perfectly fine on non-samsung devices.
Example project at: https://github.com/behelit/SamsungAnimationFailSample
The image below has a frozen ripple, no touch is occurring at this point
My solution was to pause all animations onPause and resume in onResume.
I created a button and wanted it to move to the bottom of the screen after some event is triggered. So I made an TranslateAnimation object
private TranslateAnimation setupAnimation(float yOffset) {
TranslateAnimation animation = new TranslateAnimation(0, 0, 0, yOffset);
animation.setDuration(1000);
animation.setFillAfter(true);
animation.setInterpolator(new AccelerateDecelerateInterpolator());
return animation;
}
Then I pass in the TranslateAnimation object into the startAnimation() method of the view I wanted to move.
Well that works for what I want to accomplish visually, but I noticed that I can't click on where it is visibly, but I can press where the button used to be and the onClick callback will be executed.
What do I need to do, post translation, to allow the user to press the button at its new location?
A TranslateAnimation only moves the pixels on the screen, it does not change the actual position of your Button, it just looks like it is moving, so your OnClick/OnTouchListener will not animate with it.
Use ObjectAnimator or ViewPropertyAnimator to really change the property of your Button.
Here is an example using ViewPropertyAnimator to get you started :
yourButton.animate()
.translationY(yOffset)
.setInterpolator(new AccelerateDecelerateInterpolator())
.setDuration(1000);
check the Docs for other available methods.
I am making a app where the user presses a button and it tells them if they did something right or wrong, so the feedback is going to be an image that appears at the top of the view. The image will either say "Correct!" or "Incorrect". I am imagining this image sliding down at the top of the view when the user submits their answer, stays at the top for a little while, and then slides back up.
I am new to android dev and I am not sure how to do this. Would this count as an animation? How do I get the bitmap to stay for x amount of time ?
I would recommend using AnimationSet - first animation to slide down, second to slide back up. The second one should have delayed start time of the amount of time that defines "a bit" to you.
For example:
Animation hide = new TranslateAnimation(Animation.ABSOLUTE, 0, Animation.ABSOLUTE, 0, Animation.ABSOLUTE, 0, Animation.ABSOLUTE, yDelta);
hide.setDuration(animationDuration);
hide.setFillAfter(true);
Animation show = new TranslateAnimation(Animation.ABSOLUTE, 0, Animation.ABSOLUTE, 0, Animation.ABSOLUTE, yDelta, Animation.ABSOLUTE, 0);
show.setDuration(animationDuration);
show.setStartOffset(hide.getDuration() + /* delay */);
show.setFillAfter(true);
AnimationSet moveMenu = new AnimationSet(true);
moveMenu.addAnimation(hide);
moveMenu.addAnimation(show);
mMenuView.startAnimation(moveMenu);
I'm sure I'm missing something obvious but I'm unable to get my ViewFlipper to animate smoothly from one layout to the next.
My desire is to have the animation move at a constant speed. Not to accel or decel. The overall desired effect is to have the flipper animate in perpetuity with no visible stutter or hiccup, so that the two (or more) layouts just keep moving along, as though on a looped reel.
However, when I don't set an Interpolation it defaults to *some default built-in interpolation that slows down to 0 towards the end.
And when I *do set the Interpolation there's no number I seem to be able to pass in to give me the smooth animation result. 0 stops the animation outright and 1 does (seemingly) what the default does.
What am I overlooking?
here's my animation method that I am passing (as part of my custom Animation to the ViewFlipper:
public Animation inFromRightAnimation(int duration) {
Animation inFromRight = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, +1.0f, Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f
);
inFromRight.setDuration(duration);
AccelerateInterpolator ai = new AccelerateInterpolator();//tried 0 and 1.0f as params without success
inFromRight.setInterpolator(ai); //
return inFromRight;
}
Try using LinearInterpolator instead of AccelerateInterpolator. LinearInterpolator ensures that your views will move with a constant velocity without any acceleration or deceleration.
I am rotating a rectangle area view and applying the transformation after in this manner
AnimationSet snowMov1 = new AnimationSet(true);
RotateAnimation rotate1 = new RotateAnimation(0,-90, Animation.RELATIVE_TO_SELF,0.0f , Animation.RELATIVE_TO_SELF,0.0f );
rotate1.setDuration(000);
snowMov1.addAnimation(rotate1);
TranslateAnimation trans1 = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 1.0f);
trans1.setDuration(000);
snowMov1.addAnimation(trans1);
snowMov1.setFillAfter(true); //this will apply the animation and keep the transformation
This however does not rotate the focus area of that view. The focus area remains the same.
Can someone please help me how the focus area can be rotated as well ??
Thank you.
Unfortunately, there is no way to do this automatically. Animations only update the drawing position of views, and not their actual position. Your best bet here would be to set a listener for the animation and to actually change the position in the onAnimationEnd method.