A012-anim resources, androidanim

Source: Internet
Author: User

A012-anim resources, androidanim

Anim resources refer to View Animation in Android. However, View Animation is divided:
-Tween Animation)
-Frame Animation (Frame-by-Frame Animation)

Tween Animation

File Path: res/anim/filename. xml
Such a resource points to an Animation object
Resource reference:
-Reference in Java: R. anim. filename
-Reference in XML: @ anim/filename

Syntax
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android"    android:interpolator="@[package:]anim/interpolator_resource"    android:shareInterpolator=["true" | "false"] >    <alpha        android:fromAlpha="float"        android:toAlpha="float" />    <scale        android:fromXScale="float"        android:toXScale="float"        android:fromYScale="float"        android:toYScale="float"        android:pivotX="float"        android:pivotY="float" />    <translate        android:fromXDelta="float"        android:toXDelta="float"        android:fromYDelta="float"        android:toYDelta="float" />    <rotate        android:fromDegrees="float"        android:toDegrees="float"        android:pivotX="float"        android:pivotY="float" />    <set>        ...    </set></set

<set> <alpha> <scale> <translate> <rotate>
These labels can all be used as root labels to represent an animation.<set>You can include all the preceding labels.<set>And other tag combinations to design a variety of animation effects.
The functions of tag parsing are as follows:

<set>

Represents an AnimationSet
Attribute:
-Android: interpolator)
-Android: generator interpolator (whether to share the interpolation tool among all elements)

<alpha>

Represents an AlphaAnimation, fade in and out animation
Attribute:
-Android: fromAlpha (start transparency, 0.0-completely transparent 1.0-not completely transparent)
-Android: toAlpha (end transparency, 0.0-completely transparent 1.0-not completely transparent)

<scale>

Represents a ScaleAnimation, scaling Animation
Attribute:
-Android: fromXScale (scale relative to itself in the X direction at the beginning, 1.0 indicates no change)
-Android: toXScale (the zooming ratio of X to itself at the end)
-Android: fromYScale (scale relative to itself in the Y direction at the beginning)
-Android: toYScale (the zooming ratio of Y to itself at the end)
-Android: zoomed TX (scaled X axis position, 50 indicates absolute position, 50% indicates relative self, 50% p indicates relative parent Control)
-Android: Ty (zooming the Y axis, with the same value as above)

<translate>

Represents a TranslateAnimation, an offset Animation
-Android: fromXDelta (position on the X coordinate when the animation starts)
-Android: toXDelta (position on the X coordinate when the animation ends)
-Android: fromYDelta (position on Y coordinate when the animation starts)
-Android: toYDelta (position on Y coordinate when the animation ends)

Example:
Android: toXDelta = "100%", indicating its own 100%, that is, starting from the View's own position
Android: toXDelta = "80% p", indicating the 80% of the parent View, which is based on its parent View

<rotate>

Represents a RotateAnimation, rotating Animation
Attribute:
-Android: fromDegrees (animation start angle)
-Android: toDegrees (angle at animation end)
-Android: Rotate TX (X coordinate of the rotation center)
-Android: Rotate ty (Y coordinate of the rotation center)

Animation example:

<set xmlns:android="http://schemas.android.com/apk/res/android"    android:shareInterpolator="false">    <scale        android:interpolator="@android:anim/accelerate_decelerate_interpolator"        android:fromXScale="1.0"        android:toXScale="1.4"        android:fromYScale="1.0"        android:toYScale="0.6"        android:pivotX="50%"        android:pivotY="50%"        android:fillAfter="false"        android:duration="700" />    <set        android:interpolator="@android:anim/accelerate_interpolator"        android:startOffset="700">        <scale            android:fromXScale="1.4"            android:toXScale="0.0"            android:fromYScale="0.6"            android:toYScale="0.0"            android:pivotX="50%"            android:pivotY="50%"            android:duration="400" />        <rotate            android:fromDegrees="0"            android:toDegrees="-45"            android:toYScale="0.0"            android:pivotX="50%"            android:pivotY="50%"            android:duration="400" />    </set></set>

Use in code:

ImageView image = (ImageView) findViewById(R.id.image);Animation hyperspaceJump = AnimationUtils.loadAnimation(this, R.anim.hyperspace_jump);image.startAnimation(hyperspaceJump);
Frame Animation

File Path: res/drawable/filename. xml
Such a resource points to an AnimationDrawable object.
Resource reference:
-Reference in Java: R. drawable. filename
-Reference in XML: @ drawable/filename

Syntax

<?xml version="1.0" encoding="utf-8"?><animation-list xmlns:android="http://schemas.android.com/apk/res/android"    android:oneshot=["true" | "false"] >    <item        android:drawable="@[package:]drawable/drawable_resource_name"        android:duration="integer" /></animation-list>

Attribute:
-Android: oneshot (whether to play only once)

Example:

<?xml version="1.0" encoding="utf-8"?><animation-list xmlns:android="http://schemas.android.com/apk/res/android"    android:oneshot="false">    <item android:drawable="@drawable/rocket_thrust1" android:duration="200" />    <item android:drawable="@drawable/rocket_thrust2" android:duration="200" />    <item android:drawable="@drawable/rocket_thrust3" android:duration="200" /></animation-list>

An item indicates a frame, a frame corresponds to an image, and duration indicates the duration.

Use in code:

ImageView rocketImage = (ImageView) findViewById(R.id.rocket_image);rocketImage.setBackgroundResource(R.drawable.rocket_thrust);rocketAnimation = (AnimationDrawable) rocketImage.getBackground();rocketAnimation.start();

This section describes the knowledge points and usage of anim resources in Android. For more information, visit the following address:
Http://www.android-doc.com/guide/topics/resources/animation-resource.html

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.