Basic animation implementation on Android studio (first article)

Source: Internet
Author: User

Hello, dear friends, when many small partners have just started to learn Android, there are often some project needs to have some basic animation insert, then how to implement it? Let's take a look at some of the basic animations in Android.

(This is the default for Android studio, which is more intelligent than eclipse.) PS: The method is the same, no difference, like the common eclipse friends do not take offense oh. )

Before we do the specific learning of Android animation, first of all, we have to know: in Android animation is generally related to the operation of the event, for example, by triggering an event generated. Okay, here we go:

First: First we need to know that there are four main types of basic animations in Android:

1:tween Animation. Transforming animations

2:layout Animation Layout Animation

3:frame Animation. Frame animation

4:property Animation Property Animation

Learn the first two methods in this article.

Second: Animation learning

one : Tween Animation Transform Animation:

In the transformation animation is divided into basic four kinds:

1:alpha: Gradient Transparency Animation type

2:scale: Gradient Dimension Animation type

3:translate: Position Move Animation type

4:rotate: Rotate Animation type

The properties that are common to all four of these methods are the same, and the properties are as follows :

1,duration: Indicates the duration of the animation, in milliseconds, typically implemented in Java, such as Button.setduration;(where button is a reference, 1000 milliseconds, which is the duration of the animation. )

2,fillafter: Indicates that the animation transformation is applied after the end of the animation, that is, for example, in translate, the animation may run as a translation, fillafter that is, after the end of the animation determines where the animated object is located. The return value is a Boolean value, which is true when the end is set at the end of the position, or false to indicate the end of the position before the animation begins to jump back.

3,fillbefore: Animation transformation in the position before the beginning of the animation, can understand and fillafter mutual understanding.

4,interpolator: Animation insert (for an acceleration of an animation, the action of the reducer)

5:repeatcount: The number of times the animation repeats, and the definition of the repeating animation.

6:repeatmode: Determines whether the animation repeats sequentially or in reverse order.

7,startoffset: The time interval between animations and animations (typically for continuous playback of two or more animations, or to set up listeners instead of this feature)

So in the animation implementation of this piece, in addition to Java can be implemented, you can also use the layout call to implement (the following will be said)

In Java, there are several types:

1,alphaanimation has the parameter fromalpha: the transparency at the beginning, Toalpha: The transparency after the end is expressed in (0.0f to 1.0f) F for floating-point numbers.

2,scaleaniamtion have Fromx,tox, Fromy,toy, and Pirotx,prioty parameters, respectively, representing the position of the coordinates at the start and end, and where the x, y coordinates begin.

3,translateanimation with Parameters FromX The Delta,fromydelta is the starting coordinate for the first x, Y, and Toxdelta,toydelta, respectively, of the x, Y coordinates at the end.

The 4,rotateanimation has a set parameter fromdegrees starting angle, todegrees terminating angle, and Pirotx,prioty parameters.

OK, let's start with an example:

First, the Java language is used to implement a simple alpha animation,

1 New Alphaanimation (0.1f,1.0f); 2 zhangch.setduration (); 3 image.startanimation (ZHANGCH);

The argument in the first row is because of the floating-point number, so to add the letter F after each digit, the two parameters mean that the first point of the animation when running this object is to start from 0.1 transparency into the second parameter 1.0 transparency, 1.0 is the normal picture, 0.0 is all transparent.

The second line is to set the run time for the animation to 2 seconds, 2000 milliseconds.

The third line refers to the object image that starts the animation.

However, in addition to the Java code can be implemented in Android, you can also use the Res file to create a new layout file to invoke the implementation,

1 Animation zhangch = animationutils.loadanimation (this, R.anim.scale); 2 image.startanimation (ZHANGCH);

The first line of the animationutils is a system comes with the tool class, Loadanimation is loaded animation, the inside parameters refers to from the current interface call res inside the Anim folder of the scale file, the first set for the res file, The second one is the layout inside the scale:

Specific examples are as follows:

Perform an animated demonstration of the above icon as shown in the UI interface,

Where Continue_btn and continue_btn2 are a combination of two basic animations, take a look at the required constructs first

A total of two Java files, two layout files, here we only use Java code to implement the animation without layout call because the Java code animation can be more adaptable to dynamic transformation and management, as a code person should ensure that the code first choice.

First layout layouts

And then two more relativelayout, remember to set an ID name.

Here's the Code section:

Here we need a simple explanation for the implementation of this continuous animation: We use a Setup listener procedure, write down two animations in the case execution, start an animation and set a animation for the animation.

Listener, the system will automatically generate the following three states, we can literally see, as long as the execution of the end state command to add a sentence, start another animation will be able to achieve a continuous two animation playback, if there are more than one, you can set more.

Of course there are commonly used animations on one page when jumping to another page, as shown below, where:

Overridependingtransition The first parameter indicates the first activity to exit the animation, the second parameter represents the second activity enters the animation, here with the layout call,

The rotate layout is as follows:

Interpolator is the animated insert inside the previously spoken property.

OK, so this is the basic implementation of the first basic animation, below we say the second basic animation, frameanimation

The principle of frames-by-frame animation is to play a picture object at a certain speed so that people produce the illusion of continuous animation. Here is an example to explain

Create an XML file under Drawable, write a list of multiple objects in an XML file, and add a definite value in it,

The Code section and the third underlying animation are put together, layoutanimation

Layout animations have sub-setorder control sequence and Layoutanimationcotroller layout controller

For example, in Java, the route is the layout animation name:, move is the frame animation name.

Write in a new main3activity:

and write the list file in the layout file.

can be run.

Good all the code package will be analyzed in the following download, about the property animation is more complex, the next lecture will be specifically explained, I hope to help everyone, O (∩_∩) o Thank you.

Source Android file address is Https://pan.baidu.com/s/1jHEi9Hs

If there are any deficiencies, you are welcome to criticize.

Basic animation implementation on Android studio (first article)

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.