"Android Advanced" Android all kinds of animation how to use the detailed

Source: Internet
Author: User

I. Overview

Android Several animation types are available: View Animation , drawable Animation , Property Animation .

viewanimation quite simple, but only support simple zoom, pan, rotate, transparency basic animation, and have certain limitations.

drawable Animation is the so-called frame animation, generally as drawable background use.

propertyanimation produce the reason that you want View There is a color switch animation; you want to be able to use 3D you want to be animated when the animation stops . View Position is the current position; View Animation Can not be done.

Ii. Methods of Use

(1 ) view Animation (animation of a component)

     A. takes the definition xml animation, which can be used in a set The resource defines a variety of effects, use this method to pay attention to the use of the coordinates inside, is the current component of the left edge as the origin. You can use the x%p This defines the relationship to the parent layout. Use animationutils.loadanimation (context, ID) when loading in code; method to get animated and use the component's huojianimageview.setanimation (); method to animate the that can be used when the animation is started. animation Start, or you can use the component's start method.

B. Adopt Java code generation animations, translateanimation , alphaanimation . Create an animation after the Setup method as before.

(2)drawable Animation(continuous change of animation)

define animation-list in drawable and then as a component background, in Java the code gets

Animationdrawable animationdrawable = (animationdrawable) bullimageview.getbackground ();

then start animationdrawable.start ()

The general use of this method requires that the component disappears when the last frame of the animation is controlled to finish playing.

A ImageView code can be customized as follows:

Package Com.animal.bull;import Java.lang.reflect.field;import Android.content.context;import Android.graphics.canvas;import Android.graphics.drawable.animationdrawable;import Android.util.AttributeSet; Import Android.view.view;import Android.widget.imageview;public class MyImage extends ImageView {animationdrawable Animationdrawable;int Totalframe; Field field;public void setanimationdrawable (animationdrawable animationdrawable) {this.animationdrawable = Animationdrawable;totalframe = Animationdrawable.getnumberofframes ();} Public MyImage (context context, AttributeSet Attrs) {Super (context, attrs);//TODO auto-generated constructor stub}@  overrideprotected void OnDraw (canvas canvas) {//TODO auto-generated method Stubtry {if (animationdrawable! = null) {field = AnimationDrawable.class.getDeclaredField ("Mcurframe"); Field.setaccessible (true); int r = Field.getint ( animationdrawable); if (r = = totalFrame-1) {setvisibility (view.invisible);}}} catch (Exception e) {//TODO auto-generated catch blOcke.printstacktrace ();} Super.ondraw (canvas);}}

"Android Advanced" Android all kinds of animation how to use the detailed

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.