Android: Several common animations about animation

Source: Internet
Author: User

Add some animations appropriately to get a better user experience, this time talking about some common animations ~
Such as: Transparent animation, gradient animation and so on.

First look at the run:

Attach the code, and the comments are written in the code:

Mainactivity.java:

 PackageCom.vrinux.animotiondemo;Importandroid.app.Activity;ImportAndroid.os.Bundle;ImportAndroid.view.View;ImportAndroid.view.animation.AlphaAnimation;ImportAndroid.view.animation.Animation;ImportAndroid.view.animation.AnimationSet;ImportAndroid.view.animation.RotateAnimation;ImportAndroid.view.animation.ScaleAnimation;ImportAndroid.view.animation.TranslateAnimation;ImportAndroid.widget.ImageView; Public  class mainactivity extends Activity {    PrivateImageView imgobj;PrivateAnimation Animation;PrivateAnimationset Animationset;@Override    protected void onCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate);        Setcontentview (R.layout.activity_main);    Imgobj = (ImageView) Findviewbyid (R.id.imgid); } Public void Animationshow(View view) {Switch(View.getid ()) { CaseR.id.btn01id:/** * Transparent animation: alphaanimation (float fromalpha,//The alpha value of the starting state; float * toalpha)//The alpha value of the change-over state; */Animation =NewAlphaanimation (0.0F1.0f);//Set the duration of the animation;Animation.setduration ( the);//Add animations for components;Imgobj.setanimation (animation); Break; CaseR.id.btn02id:/** * Gradient animation: scaleanimation (float FromX,//Change start state x-axis (that is, width) is the ratio of the control's x-axis (that is, width), * 1.0f is the width of the control, 0.0f means no width , which is greater than the corresponding multiple of the width of the 1.0f identity control; float * tox,//Changes the end state x-axis (that is, the width) of the control's x-axis (that is, the width); float fromY, *//change the starting state y-axis (that is, height) of the control  The ratio of y-axis (that is, height), and fromx; float toY, *//change end state Y-axis (that is, height) is the ratio of the y-axis (i.e. height) of the control, the x-coordinate of the origin of the change of float pivotx,//; float * PIVOTY)//Change the origin y-axis coordinates; */Animation =NewScaleanimation (0.5F2.0F0.5F2.0F50.0F50.0f); Animation.setduration ( the); Imgobj.setanimation (animation); Break; CaseR.id.btn03id:/** * Displacement animation: translateanimation (float fromxdelta,//displacement start x axis position; float * Toxdelta,//Displacement end x-axis position; Flo At Fromydelta,//Displacement starting y-axis position; float * toydelta)//Displacement end y-axis position; * /Animation =NewTranslateanimation (0.0F100.0F0.0F100.0f); Animation.setduration ( the); Imgobj.setanimation (animation); Break; CaseR.id.btn04id:/** * Rotation animation: rotateanimation (float fromdegrees,//start rotation degree; float * todegrees,//end rotation degree; float PIV OtX,//x-axis coordinates of the rotation origin, float * pivoty)//y-coordinate of the rotation origin; * /Animation =NewRotateanimation (0.0F360.0F50.0F50.0f); Animation.setduration ( the); Imgobj.setanimation (animation); Break; CaseR.id.btn05id:/** * Animationset (TRUE)//animation collection (combination);Alphaanimation Animation1 =NewAlphaanimation (0.0F1.0f); Scaleanimation Animation2 =NewScaleanimation (0.5F2.0F0.5F2.0F50.0F50.0f); Translateanimation Animation3 =NewTranslateanimation (0.0F100.0F0.0F100.0f); Rotateanimation Animation4 =NewRotateanimation (0.0F360.0F50.0F50.0f); Animationset =NewAnimationset (true);            Animationset.addanimation (Animation1);            Animationset.addanimation (Animation2);            Animationset.addanimation (Animation3);            Animationset.addanimation (ANIMATION4); Animationset.setduration (4000); Imgobj.setanimation (Animationset); Break; }    }}

Activity_main.xml:

<linearlayout xmlns:android="Http://schemas.android.com/apk/res/android"Android:layout_width="Fill_parent"android:layout_height="Fill_parent"android:orientation="Vertical"> <imageview android:ID="@+id/imgid"Android:layout_width="200DP"android:layout_height="200DP"android:layout_weight="1"Android:src="@drawable/img"/> <button android:ID="@+id/btn01id"Android:layout_width="Match_parent"android:layout_height="Wrap_content"android:layout_weight="1"android:onclick="Animationshow"Android:text="Transparent animation"Android:textsize="20SP"/> <button android:ID="@+id/btn02id"Android:layout_width="Match_parent"android:layout_height="Wrap_content"android:layout_weight="1"android:onclick="Animationshow"Android:text="Gradient Animation"Android:textsize="20SP"/> <button android:ID="@+id/btn03id"Android:layout_width="Match_parent"android:layout_height="Wrap_content"android:layout_weight="1"android:onclick="Animationshow"Android:text="Displacement animation"Android:textsize="20SP"/> <button android:ID="@+id/btn04id"Android:layout_width="Match_parent"android:layout_height="Wrap_content"android:layout_weight="1"android:onclick="Animationshow"Android:text="Rotate animation"Android:textsize="20SP"/> <button android:ID="@+id/btn05id"Android:layout_width="Match_parent"android:layout_height="Wrap_content"android:layout_weight="1"android:onclick="Animationshow"Android:text="Animation Mix"Android:textsize="20SP"/></linearlayout>

Photo resources:

Img.jpg:

Android: Several common animations about 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.