Android animation (2) Declare files and associated files through animation layout for container Layout-layout Animation

Source: Internet
Author: User

First:

Of course, you cannot see the dynamic animation effect here. Of course, if you run the author's code, you can naturally see the animation effect. The effect here is the animation effect that is presented to us before each item in our list is finally displayed as shown in.

Let's take a look at the activity code:

Package cn.com. chenzheng_java.animation; </P> <p> Import android. app. activity; <br/> Import android. OS. bundle; <br/> Import android. widget. arrayadapter; <br/> Import android. widget. listview; <br/>/** <br/> * @ description layout animation <br/> * What is layout Animation: Make the view in the container into an animation, it is a complementary animation. When <br/> * in the previous example, we want to make the content in the listview container animated <br/> * @ author chenzheng_java <br/> * @ since 2011/03/24 <br/> */<br/> public class animation2activity extends Activity {<br/> listview; <br/> string [] city = new string [] {<br/> "Zhongguancun", <br/> "Haidian theatre", <br/> "Haidian hospital ", <br/> "Renmin University" <br/>}; </P> <p> @ override <br/> protected void oncreate (bundle savedinstancestate) {<br/> super. oncreate (savedinstancestate); <br/> setcontentview (R. layout. animation2); <br/> listview = (listview) findviewbyid (R. id. listview_animation2); <br/> arrayadapter <string> adapter = new arrayadapter <string> (this, android. r. layout. simple_list_item_1, city); <br/> listview. setadapter (adapter); <br/>}</P> <p>

Animation2.xml layout file:

 

<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" <br/> Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" <br/> Android: orientation = "vertical"> <br/> <listview Android: layout_width = "fill_parent" <br/> Android: Id = "@ + ID/listview_animation2" <br/> Android: persistentdrawingcache = "animation | scrolling" <br/> Android: layoutanimation = "@ anim/animation2_drawable" <B R/> Android: layout_height = "wrap_content"> </listview> <br/> </linearlayout> <br/> <! -- <Br/> we can see that two animation-related attributes are set in the layout settings of listview: <br/> Android: persistentdrawingcache: This attribute is recommended, it optimizes the animation and scrolling effects. <Br/> Android: layoutanimation: Specifies the animation Association file corresponding to the current layout container. Note: The animation Association file is specified here, not the animation declaration file. <br/> -->

Animation declaration file:

Scale_anim.xml

<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <set xmlns: Android = "http://schemas.android.com/apk/res/android" <br/> Android: interpolator = "@ Android: anim/accelerate_interpolator "> <br/> <scale <br/> Android: fromxscale =" 1 "<br/> Android: toxscale =" 1 "<br/> Android: fromyscale = "0.1" <br/> Android: toyscale = "1.0" <br/> Android: Duration = "1000" <br/> Android: required Tx = "50%" <br/> Android: Required ty = "50%" <br/> Android: startoffset = "100"> <br/> </scale> </P> <p> </set> <Br/> <! -- <Br/> the animation declaration file is located in the Res/anim folder. <br/> define the animation behavior: <br/> Android: fromxscale = "1" <br/> Android: toxscale = "1" specifies the X axis without scaling </P> <p> Android: fromyscale = "0.1" <br/> Android: toyscale = "1.0" specifies that the method starts from on the Y axis, zoom in until normal size </P> <p> Android: Duration = "1000" animation display time </P> <p> Android: required Tx = "50%" <br/> Android: Required ty = "50%" is in the middle of the animation execution, the object size is 50% on the x/y axis </P> <p> Android: startoffset = "100" the number of milliseconds that are waiting before the animation is executed <br/> -->

Animation associated files:

Animation2_drawable.xml

<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <layoutanimation xmlns: Android = "http://schemas.android.com/apk/res/android" <br/> Android: delay = "30%" <br/> Android: animationorder = "reverse" <br/> Android: animation = "@ anim/scale_anim" <br/> </layoutanimation> </P> <p> <! -- Animation associated file: this file is located in the Res/anim folder <br/> this file is the intermediate medium of the container and the animation declaration file. It is bound to an animation declaration file, <br/> some playing attributes of the animation are set, for example, <br/> Android: each delay animation should be executed at 30% of the total time of the animation delay (multiple animations are used in the current list). <br/> the total time of the delayed animation corresponds to Android in the animation declaration file: total startoffset <br/> Android: animationorder: sequence of animation execution in the list (used when multiple animations exist in the current list) <br/> Android: animation declaration file specified by animation <br/> -->

 

The comments in the Code have been quite clear, so I will not say much. Note that in the layout file, the positions of the animation declaration file and the animation associated file are all in the Res/anim folder.

Bytes -----------------------------------------------------------------------------------------------

The above only shows a scaling animation. What other common animations do?

<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <set xmlns: Android = "http://schemas.android.com/apk/res/android" <br/> Android: interpolator = "@ Android: anim/accelerate_interpolator"> <br/> <! -- Rotate: rotates the animation around the center of the text. --> <br/> <rotate <br/> Android: fromdegrees = "0.0" <br/> Android: todegrees = "360" <br/> Android: 0000ty = "50%" <br/> Android: 0000tx = "50%" <br/> Android: duration = "5000" <br/> </rotate> <br/> <! -- Translate indicates a mobile animation. The animation moves the text from the top of the currently allocated display space to the bottom --> <br/> <translate <br/> Android: fromydelta = "-100%" <br/> Android: toydelta = "0" <br/> Android: duration = "10000" <br/> </translate> <br/> <! -- Alpha represents the visibility gradient animation, which is invisible and completely visible --> <br/> <Alpha <br/> Android: fromalpha = "0.0" <br/> Android: toalpha = "1.0" <br/> Android: Duration = "3000" <br/> </alpha> <br/> </set> <br/>

Here, we can see that no matter which animation declaration file contains such a line of code:

Android: interpolator = "@ Android: anim/accelerate_interpolator"

So what is the use of this line of code?

This is called an interpolation in Android. It tells the system the implementation details of our animation. For example, does a color change linearly or exponentially over time? Or is it very fast at the beginning, and then it gradually slows down?

We all know that the @ Android method represents an XML layout file provided by the Android system. In fact, this layout file is the ing of the next class of Android. View. animation. This category of classes mainly includes:

Acceleratedecelerateinterpolator

Accelrateinterpolator

Cycleinterpolator

Linearinterpolator

......

 

 

 

 

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.