Android animation implementation XML Attribute configuration description animutil tool class

Source: Internet
Author: User
Tags xml attribute

Project requirements: Text scrolling is required. Considering that there are two ways to implement animations in Android, Tween and flame, we still need to use tween after reading the materials, I wrote a tool class animutil, which calls the tool class to implement the view animation effect. In order to facilitate the update of the View Interface, animutil also integrates the self-handler. The specific reference code is as follows:

package com.vtion.sleb.banca.utils;import android.content.Context;import android.os.Handler;import android.view.View;import android.view.animation.Animation;import android.view.animation.Animation.AnimationListener;import android.view.animation.AnimationUtils;import com.vtion.sleb.activities.R;public class AnimUtils extends Handler implements AnimationListener {private View view;private Animation anim_right;private Animation anim_left;public AnimUtils(View view, Context context) {anim_right = AnimationUtils.loadAnimation(context, R.anim.right_in);anim_left = AnimationUtils.loadAnimation(context, R.anim.left_out);anim_right.setAnimationListener(this);anim_right.setFillAfter(true);anim_left.setFillAfter(true);this.view = view;this.view.startAnimation(anim_right);}@Overridepublic void onAnimationEnd(Animation animation) {this.postDelayed(new Runnable() {@Overridepublic void run() {view.startAnimation(anim_left);}}, 2000);}@Overridepublic void onAnimationRepeat(Animation animation) {}@Overridepublic void onAnimationStart(Animation animation) {System.out.println();System.out.println();}}

The anim folder contains the animation-related xml configuration files:

<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" >    <translate        android:duration="700"        android:fromXDelta="100%p"        android:toXDelta="50%p" />    <alpha        android:duration="700"        android:fromAlpha="0.1"        android:toAlpha="1.0" /></set>
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" >    <translate        android:duration="700"        android:fromXDelta="50%p"        android:toXDelta="0" />    <alpha        android:duration="700"        android:fromAlpha="1.0"        android:toAlpha="0.0" /></set>

Supplement:

Introduction to the attributes of animation configuration in XML files

ALPHA:Gradient transparency animation effect

Scale:Gradient scaling animation effect

Translate:Mobile animation effect

Rotate:Rotating animation effect


  1. <! --
  2. Fromxscale [float]: The scaling size on the X coordinate at the start of the animation. The value 0.0 indicates that the scale is reduced to none.
  3. Fromyscale [float]: The scaling size on the Y coordinate at the start of the animation. The value 0.0 indicates that the scale is reduced to none.
  4. 1.0 indicates normal scaling-free
  5. A value smaller than 1.0 indicates contraction.
  6. Value greater than 1.0 indicates Amplification
  7. Toxscale [float]: The scaling size on the X coordinate when the animation ends.
  8. Toyscale [float]: The scaling size on the X coordinate when the animation ends.
  9. Horizontal TX [float]: the starting position of the animation relative to the X coordinate of the object
  10. Interval ty [float]: the starting position of the animation relative to the X and Y coordinates of the object.
  11. 50,50%, 50% p. The three statements represent absolute, relative_to_self, and relative_to_parent respectively.
  12. Attribute value description: from 0%-100%, 50% is the midpoint position on the X or Y coordinate of the object.
  13. Fillafter [Boolean]: when it is set to true, the animation is applied after the animation ends.
  14. Startoffset [long]: The time interval between animations, starting from the time when the animation was stopped.
  15. Repeatcount [int]: Number of animation repetitions -->

Interpolator: Specifies an animation insertor to control the animation speed changes.

Fromalpha: Transparency 0.0 indicates full transparency 1.0 indicates full transparency at the beginning of the animation
The above value is a float data type number between 0.0 and 1.0.

Toalpha: transparency at animation end

Duration: Duration



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.