Android Learning Note-tween Animation

Source: Internet
Author: User

Android animation is divided into tween animation and frame animation, recently studied, body tween animation, now talk about learning and related knowledge introduced as follows.

Tween, also known as tweened animation, allows you to zoom in, zoom in, rotate, and gradient.

First: Tween animation four main implementation classes:1, Alphaanimation: gradient (color) animation, mainly control the transparency change animation class, often using alphaanimation (float fromalpha, float toalpha) to construct;    Fromalpha: Transparency at the beginning of the animation (range from 0.0 to 1.0);    Toalpha: Transparency at the end of the animation, 2, Scaleanimation: Main control size change, Often used scaleanimation (float FromX, float toX, float fromY, float toY, int pivotxtype, float pivotxvalue, int pivotytype, float Pivotyvalue) to construct;    FromX: The scaling scale (relative to the size of the original picture) on the x-coordinate of the animation;    ToX: The scaling scale on the x-coordinate of the animation end;     FromY: The scaling scale on the y-coordinate of the animation start;    ToY: The scaling scale on the end of the animation y-coordinate;    PIVOTXTYPE:X coordinates on the scaling mode (type), the value is: Animation.absolute, animation.relative_to_self: relative to itself, animation.relative_to_parent;     PIVOTXVALUE:X coordinates on the center position of the scaling;    pivotytype:y coordinates on the scaling mode, the value is: Animation.absolute, Animation.relative_to_self, the center position of the animation.relative_to_parent;    pivotyvalue:y coordinates; 3. Translateanimation: The main control position transformation of the animation implementation class, often using translateanimation (float Fromxdelta, float toxdelta, float fromydelta, float Toydelta) to construct the;   Fromxdelta: The x-coordinate of the start of the animation;    Toxdelta: The x-coordinate of the end of the animation;    Fromydelta: The y-coordinate of the animation start;     Toydelta: The y-coordinate of the end of the animation, 4, Rotateanimation: The main control of the rotation of the animation implementation class, often used rotateanimation (float fromdegrees, float todegrees, int Pivotxtype, float pivotxvalue, int pivotytype, float pivotyvalue) to construct;    fromdegrees: rotation start angle;     todegrees: Rotation End angle;    pivotxtype, Pivotxvalue, Pivotytype, Pivotyvalue and scale change animation scaleanimation similar;  Second: The shared methods that are includedSet playback time

Animation.setduration (2000);

Set the number of repetitions, remembering the number of repetitions

Animation.setrepeatcount (2);

//Set Duplicate mode, there are two kinds of restart: Restart with REVERSE: Reverse Start

Animation.setrepeatmode (Alphaanimation.reverse);

//Start play

Iv.startanimation (animation);

Third: examples,

Layout file We write this,

<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"

Xmlns:tools= "Http://schemas.android.com/tools"

Android:layout_width= "Match_parent"

android:layout_height= "Match_parent"

android:orientation= "Vertical"

android:paddingbottom= "@dimen/activity_vertical_margin"

android:paddingleft= "@dimen/activity_horizontal_margin"

android:paddingright= "@dimen/activity_horizontal_margin"

android:paddingtop= "@dimen/activity_vertical_margin"

tools:context= "Com.ftf.tween.MainActivity" >

<linearlayout

Android:layout_width= "Fill_parent"

android:layout_height= "Wrap_content"

android:orientation= "Horizontal" >

<button

android:onclick= "click"

android:text= "Transparency"

Android:layout_width= "Wrap_content"

android:layout_height= "Wrap_content"

android:orientation= "Horizontal"/>

<button

android:onclick= "Click2"

android:text= "Zoom"

Android:layout_width= "Wrap_content"

android:layout_height= "Wrap_content"

android:orientation= "Horizontal"/>

<button

android:onclick= "Click3"

android:text= "Rotate"

Android:layout_width= "Wrap_content"

android:layout_height= "Wrap_content"

android:orientation= "Horizontal"/>

<button

android:onclick= "Click4"

android:text= "Panning"

Android:layout_width= "Wrap_content"

android:layout_height= "Wrap_content"

android:orientation= "Horizontal"/>

<button

android:onclick= "Click5"

android:text= "Combination"

Android:layout_width= "Wrap_content"

android:layout_height= "Wrap_content"

android:orientation= "Horizontal"/>

</LinearLayout>

<linearlayout

Android:layout_width= "Match_parent"

android:layout_height= "Match_parent"

android:gravity= "Center" >

<imageview

Android:id= "@+id/iv"

android:src= "@drawable/ic_launcher"

Android:layout_width= "Wrap_content"

android:layout_height= "Wrap_content"

/>

</LinearLayout>

</LinearLayout>

In the activity, write this:

Transparency changes

public void Click (View view) {

alphaanimation animation = new Alphaanimation (0.0f, 1.0f);

Animation.setduration (2000);

Animation.setrepeatcount (2);

Animation.setrepeatmode (Alphaanimation.reverse);

Iv.startanimation (animation);

}

public void Click2 (view view) {

scaleanimation animation = new Scaleanimation (0.2f, 2.0f, 0.2f, 2.0f,

Animation.relative_to_self, 0.5f, Animation.relative_to_self,

0.5f);

Animation.setduration (2000);

Animation.setrepeatcount (2);

Animation.setrepeatmode (Alphaanimation.reverse);

Iv.startanimation (animation);

}

public void Click3 (view view) {

rotateanimation animation = new Rotateanimation (0, 360,

Animation.relative_to_self, 0.5f, Animation.relative_to_self,

0.5f);

Animation.setduration (2000);

Animation.setrepeatcount (2);

Animation.setrepeatmode (Alphaanimation.reverse);

Iv.startanimation (animation);

}

public void Click4 (view view) {

translateanimation animation = new Translateanimation (

Animation.relative_to_parent, 0.2f,

Animation.relative_to_parent, 1.0f,

Animation.relative_to_parent, 0.2f,

Animation.relative_to_parent, 1.0f);

Animation.setduration (2000);

Animation.setrepeatcount (2);

Animation.setrepeatmode (Alphaanimation.reverse);

Iv.startanimation (animation);

}

public void Click5 (view view) {

//Set blending mode, that is, the multi-play effect is put together.

Animationset set = new Animationset (false);

Translateanimation pa = new Translateanimation (

Animation.relative_to_parent, 0.2f,

Animation.relative_to_parent, 1.0f,

Animation.relative_to_parent, 0.2f,

Animation.relative_to_parent, 1.0f);

Pa.setduration (2000);

Pa.setrepeatcount (2);

Pa.setrepeatmode (Alphaanimation.reverse);

Rotateanimation ra = new Rotateanimation (0, 360,

Animation.relative_to_self, 0.5f, Animation.relative_to_self,

0.5f);

Ra.setduration (2000);

Ra.setrepeatcount (2);

Ra.setrepeatmode (Alphaanimation.reverse);

Scaleanimation sa = new Scaleanimation (0.2f, 2.0f, 0.2f, 2.0f,

Animation.relative_to_self, 0.5f, Animation.relative_to_self,

0.5f);

Sa.setduration (2000);

Sa.setrepeatcount (2);

Sa.setrepeatmode (Alphaanimation.reverse);

Set.addanimation (SA);

Set.addanimation (RA);

Set.addanimation (PA);

Iv.startanimation (set);

}

Android Learning Note-tween Animation

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.