Go to] Android animation application instance

Source: Internet
Author: User
The file name is myanimation. XML, which is located in the Res/anim folder:
 
 
  1. <? XML version = "1.0" encoding = "UTF-8"?>
  2. <Set xmlns: Android = "http://schemas.android.com/apk/res/android">
  3. <! --
  4. Tween animation: animated effects are generated by constantly performing image transformations (translation, scaling, and rotation) on objects in the scenario.
  5. ALPHA: gradient transparency animation effect
  6. Scale: gradient scaling animation effect
  7. Translate: animation effect for moving the position of the screen
  8. Rotate: animation effect of screen Rotation
  9. Tween animation common attribute [type] Function
  10. The duration [long] attribute is the animation duration in milliseconds.
  11. When fillafter [Boolean] is set to true, the animation is applied after the animation ends.
  12. When fillbefore [Boolean] is set to true, the animation is applied before the animation starts.
  13. Interpolator specifies an animation plug-in that has some common plug-ins.
  14. Accelerate_decelerate_interpolator
  15. Accelerator-slowdown animation inserter
  16. Accelerate_interpolator
  17. Acceleration-animation insertor
  18. Decelerate_interpolator
  19. Slowdown-animation inserter
  20. Other animation Effects
  21. Repeatcount [int] Number of animation repetitions
  22. Repeatmode [int] defines repeated behavior 1: Start again 2: plays backward
  23. The interval between the startoffset [long] animations, starting from the time when the animation was stopped.
  24. Zadjustment [int] defines the change of Z order of the animation 0: Keep Z order unchanged
  25. 1: Keep at the top
  26. -1: Keep at the bottom layer
  27. -->
  28. <! --
  29. Transparent animation control
  30. -->
  31. <Alpha
  32. Android: fromalphi = "0.1"
  33. Android: toalpha = "1.0"
  34. Android: duration= "3000"
  35. />
  36. <! -- Scale up and down the animation effect
  37. Attribute: interpolator specifies an animation plug-in.
  38. There are three types of animation inserts:
  39. Accelerate_decelerate_interpolator acceleration-Deceleration animation inserter
  40. Accelerate_interpolator acceleration-animation insertor
  41. Decelerate_interpolator deceleration-animation insertor
  42. Other animation Effects
  43. The fromxscale attribute is the scaling size on the X coordinate when the animation starts.
  44. The toxscale attribute is the scaling size on the X coordinate when the animation ends.
  45. The fromyscale attribute is the scaling size on the Y coordinate at the start of the animation.
  46. The toyscale attribute is the scaling size on the Y coordinate when the animation ends.
  47. Note:
  48. The preceding four property values
  49. 0.0 indicates shrinking to none
  50. 1.0 indicates normal scaling-free
  51. A value smaller than 1.0 indicates contraction.
  52. Value greater than 1.0 indicates Amplification
  53. The ready TX attribute is the starting position of the animation relative to the X coordinate of the object.
  54. The ready ty attribute is the starting position of the animation relative to the Y coordinate of the object.
  55. Note:
  56. The preceding two attribute values are from 0% to 100%.
  57. 50% indicates the point position on the X or Y coordinate of the object.
  58. Long integer value:
  59. The duration attribute is the animation duration.
  60. Description: The time is in milliseconds.
  61. Boolean value:
  62. When the fillafter attribute is set to true, the animation is applied after the animation ends.
  63. -->
  64. <Scale
  65. Android: interpolator = "@ Android: anim/accelerate_decelerate_interpolator"
  66. Android: repeatcount = "1"
  67. Android: fromxscale = "0.5"
  68. Android: fromyscale = "0.5"
  69. Android: toxscale = "1.4"
  70. Android: toyscale = "1.4"
  71. Android: Required Tx = "50%"
  72. Android: Ty = "50%"
  73. Android: fillafter = "false"
  74. Android: duration= "3000"
  75. />
  76. <! --
  77. Animated effect translate
  78. Fromxdelta toxdelta is the position on the X coordinate at the animation end start.
  79. Fromydelta toydelta is the position on the Y coordinate when the animation ends.
  80. -->
  81.  
  82. <Translate
  83. Android: repeatcount = "2"
  84. Android: fromxdelta = "-30"
  85. Android: fromydelta = "-30"
  86. Android: toxdelta = "-80"
  87. Android: toydelta = "200"
  88. Android: duration= "3000"
  89. />
  90. <! --
  91. Screen transfer rotation animation effect rotate
  92. Fromdegrees indicates the object angle when the animation starts.
  93. If the angle is negative, it indicates clockwise rotation.
  94. If the angle is positive, it indicates clockwise rotation.
  95. (Negative from -- to positive: clockwise rotation)
  96. (Negative from -- to negative: counter-clockwise rotation)
  97. (Positive from -- to positive: clockwise rotation)
  98. (Positive from -- to negative: clockwise rotation)
  99. The todegrees attribute indicates that the Rotation Angle of an object can be greater than 360 degrees when the animation ends.
  100. Pivotx
  101. Ty indicates the starting position of the animation relative to the X and Y coordinates of the object. The preceding two attribute values are from 0% to 100%.
  102. 50% indicates the point position on the X or Y coordinate of the object.
  103. -->
  104. <Rotate
  105. Android: interpolator = "@ Android: anim/accelerate_interpolator"
  106. Android: repeatcount = "2"
  107. Android: fromdegrees = "0"
  108. Android: todegrees = "+ 270"
  109. Android: Required Tx = "50%"
  110. Android: Ty = "50%"
  111. Android: duration= "3000"
  112. />
  113. </Set>
Usage: add the animation definition to a textview. The work to be done is simple:
 
 
  1. Animation mAnimation ;   
  2. mAnimation = AnimationUtils.loadAnimation(this, R.anim.anim);   
  3. TextView text = (TextView)findViewById(R.id.textview00);   
  4. text.setAnimation(mAnimation);   
Note that you must use the START () method of animationdrawable to start the animation. Whether or not the animation is complete, you must first call its stop () method to start the animation for the second time () method to start the animation again.

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.