Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Animate view from off screen not working

I have a view that is positioned totally off screen and I am trying to animate it onto the screen.

When I call:

view.startAnimation(tA);

nothing happens, tA.initialize and tA.applyTransformation never get called.

If I move the view so that any part of it is visible before I start the animation, then the animation works correctly.

What is preventing a view from being animated when it is positioned off the parent View?

like image 486
RaiderJ Avatar asked Feb 12 '12 18:02

RaiderJ


People also ask

How do I animate a view in Android?

You can use the view animation system to perform tweened animation on Views. Tween animation calculates the animation with information such as the start point, end point, size, rotation, and other common aspects of an animation.

Is animation possible on Android?

On Android 4.4 (API level 19) and higher, you can use the transition framework to create animations when you swap the layout within the current activity or fragment. All you need to do is specify the starting and ending layout, and what type of animation you want to use.

How do I turn off animator on Android?

Open Settings . Scroll down and select Accessibility. Scroll down to Display and tap Text and display. Tap the toggle switch for Remove animations to turn it on.


1 Answers

It's my understanding from researching the same problem that Android Animations do not do well when provided with offscreen coordinates for their start or finish.

There is some dialog on the Android forums about this bug having been addressed but I'm still experiencing problems on 4.2.

Edit:

On second thought, I just ran across this answer and it provides a working alternative if you can use the newer APIs (ObjectAnimator).

View view = this;
ObjectAnimator anim = ObjectAnimator.ofFloat(view, "y", 0, 100);
anim.setDuration(super.animationDuration());
anim.start();

Where the properties of ObjectAnimator.ofFloat(view, "y", 0, 100); are

ObjectAnimator.ofFloat(Object objBeingAnimated, String propertyBeingAnimated, float startValue, float endValue)
like image 139
Alfie Hanssen Avatar answered Oct 15 '22 03:10

Alfie Hanssen