Animation changes in Android animation case 2

Source: Internet
Author: User

Before, I have said the next, about the blending of the transform animation. Here, I'm going to say, write an animated set of Animationset (we know that there are set containers in Java, and the set container is characterized by: 1. Unordered 2. Does not contain duplicate elements. The equivalent of a collection of mathematics is used to hold multiple animation objects, this is the method of Java code, and one way is to write a set of XML code under Anim to hold multiple animations, I use the second method here

XML code under the Anim file

XML code

1 <?XML version= "1.0" encoding= "UTF-8"?>2 <Setxmlns:android= "Http://schemas.android.com/apk/res/android"3     >4     <Alpha5         android:duration= "$"6 Android:fromalpha= "0.0"7 Android:toalpha= "1.0"8 Android:fillafter= "true"9         />Ten     <Alpha One         Android:startoffset= "$" A Android:fromalpha= "1.0" - Android:toalpha= "0.0" - android:duration= "$" the Android:fillbefore= "true" -         /> - </Set>

Layout file Code

XML code

1  <LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"2 Xmlns:tools= "Http://schemas.android.com/tools"3 Android:layout_width= "Match_parent"4 Android:layout_height= "Match_parent"5 android:orientation= "vertical"6 Tools:context= "Com.example.Tween_Animation.Alpha_MainActivity" >7 8     <Button9         Android:id= "@+id/button_scale"Ten Android:layout_width= "Fill_parent" One Android:layout_height= "Wrap_content" A Android:text= "@string/button_stringscaleanimation" /> -  -     <LinearLayout the         android:gravity= "Center" - Android:layout_width= "Fill_parent" - Android:layout_height= "Fill_parent" - android:orientation= "vertical" > +  -         <ImageView +             Android:id= "@+id/imageview_scale" A Android:layout_width= "Wrap_content" at Android:layout_height= "Wrap_content" - android:src= "@drawable/ic_launcher" /> -     </LinearLayout> -  - </LinearLayout>

Activity Code

Java code

1  PackageCom.example.Demo2;2 3 4 5 ImportCOM.EXAMPLE.ANDROIDANIMATION.R;6 7 Importandroid.app.Activity;8 ImportAndroid.os.Bundle;9 ImportAndroid.view.View;Ten ImportAndroid.view.View.OnClickListener; One Importandroid.view.animation.Animation; A Importandroid.view.animation.AnimationUtils; - ImportAndroid.widget.Button; - ImportAndroid.widget.ImageView; the  -  Public classMainactivityextendsActivityImplementsonclicklistener{ -     PrivateButton Button =NULL; -     PrivateImageView ImageView =NULL; +     protected voidonCreate (Bundle savedinstancestate) { -         Super. OnCreate (savedinstancestate); + Setcontentview (r.layout.activity_main); Abutton =(Button) Findviewbyid (R.id.button_scale); atImageView =(ImageView) Findviewbyid (R.id.imageview_scale); -Button.setonclicklistener ( This); -     } -      Public voidOnClick (View v) { -Animation Animation = animationutils.loadanimation ( This, R.anim.demo2); - imageview.startanimation (animation); in     } -}

After we can use a collection to load an animation, is not it amazing ah?

Animation changes in Android animation case 2

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.