What is the best way to animate extruded in a view using animator classes?

I read about property animation and Hardware Acceleration , but I'm still not sure what the most efficient way to use animator classes is. (For this question, I do not need to support devices prior to Honeycomb. Therefore, I want to use animator classes.)

For example, let's say I have an idea. In this view, I have a BitmapDrawable that I want to fade out. There are also many other elements in this view that will not change.

Which property or object is best used with an animator? Selectable? Paint with which I draw a bitmap using onDraw? Something else?

How to do this to be most effective with hardware acceleration? Will this require calling invalidate for each step of the animation, or is there a way to animate only the popped one, and not make the rest of the view redraw completely for each step of the animation?

I think, I think that the best case is that the rest of the review should not be completely redrawn in the software, but rather hardware acceleration that effectively fades the pushed out.

Any suggestions or pointers to recommended approaches?

Thanks!

+7
source share
3 answers

With Object Property Animators, basically, it's just mathematical functions that repeatedly call the setN () method every X miliseconds, where "N" is the property you want to change.

In the example presented in the alpha case, calling invalidate() requires redrawing the view you are animating. The difference is that you call setAlpha() on the View object, it calls invalidate() for you. If you were to set the Paint target, which is used for drawing, you still need to call invalidate() on the View to redraw the new Paint parameters.

Ideally, you want to set the goal to a child level of the highest level, so that redrawing only occurs on the views you want to animate. For example, if you set the target in the root view, it will call invalidate() for each child in the entire ViewGroup, which in turn will call draw() for each child in the ViewGroup. If you set it to the top level of ImageView , only ImageView will be redrawn.

To make better use of the equipment, you need to use the Layer properties. First, you need to decide what will be the most parental species that you want to animate. If you only want to fade Drawable , then it will be Drawable or contains a View . If you want everything to disappear, then this will be the root view. Everything that you decide to revive will be applied to the View as a whole immediately.

Use setLayerType() in the parent view just before starting Animator. Set it to View#LAYER_TYPE_HARDWARE . Then set the AnimationListener and reset LayerType to View#LAYER_TYPE_SOFTWARE or View#LAYER_TYPE_NONE after the animator completes.

 myParentView.setLayerType(View.LAYER_TYPE_HARDWARE, null); myObjectAnimator.addListener(new ViewAnimator.AnimatorListener() { public void onAnimationEnd(Animator animation) { myParentView.setLayerType(View.LAYER_TYPE_NONE); } public void onAnimationRepeat(Animator animation) { } public void onAnimationStart(Animator animation) { } public void onAnimationCancel(Animator animation) { myParentView.setLayerType(View.LAYER_TYPE_NONE, null); } } myObjectAnimator.start(); 

In this case, if you were to translate myParentView using the translateX property, it will put the myParentView layer and all its children on the same plane. Put it in the hardware memory. Translate the whole view at once. Then, upon completion, remove myParentView from memory.

EDIT:

Finally, Alpha cripples the processor. If you have something half alpha and translate it through View, it will be harder to do than if you just translated View. Use it sparingly.

+4
source

Perhaps you can overlay a new look (which contains only the animator) on your original one. The new view is set to Transparent.

the reset you have to do is not valid for a new view without the original view.

+1
source

After viewing your requests, please check out this standard document , which is neat so that you understand how to use invalidate() correctly. Secondly, the Android API is great for working with animations in different situations.

Here , I hope that most of your doubts will be cleared. Please go to the sections and the blog related to them has mentioned them.

Hope this helps you.

+1
source

All Articles