Android animation uses an animation layout to declare files and associated files 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:

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

Animation2.xml layout file:

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

Animation declaration file:

Scale_anim.xml

<? XML version = "1.0" encoding = "UTF-8"?> <Set xmlns: Android = "http://schemas.android.com/apk/res/android" Android: interpolator = "@ Android: anim/accelerate_interpolator"> <scale Android: fromxscale = "1" Android: toxscale = "1" Android: fromyscale = "0.1" Android: toyscale = "1.0" Android: Duration = "1000" Android: Large Tx = "50%" Android: Large ty = "50%" Android: startoffset = "100"> </scale> </set> <! -- Animation declaration file: this file is located in the Res/anim folder to define the specific behavior of the animation: Android: fromxscale = "1" Android: toxscale = "1" specifies the X axis, android: fromyscale = "0.1" Android: toyscale = "1.0" is not scaled. If this parameter is specified on the Y axis, the method starts from 10 to the normal size. Android: duration = "1000" the animation display time Android: Short Tx = "50%" Android: Short ty = "50%" is in the middle of the animation execution, the object size is 50% Android: startoffset = "100" on the x/y axis. The number of milliseconds that are waiting before the animation is modified -->

Animation associated files:

Animation2_drawable.xml

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

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.

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

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

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.