[Android interface implementation] View Animation usage introduction, androidanimation
Reprinted please indicate the source: http://blog.csdn.net/zhaokaiqiang1992
We can use the view animation system to add a tween animation to the View control (hereinafter referred to as the "replenishment animation"). By calculating some animation parameters, such as the start point and end point, the size, rotation angle, and other Animation Parameters to achieve the animation effect.
The compensation animation can add a series of simple transformations to the View object, such as position, size, angle, or transparency. Therefore, if you have a TextView object, you can move, rotate, or increase it. If it has a background image, the background image also changes with text.
Http://developer.android.com/reference/android/view/animation/package-summary.html this address provides all the classes required for the compensation animation.
A series of animation commands are defined as complementary animations, which can be defined using xml files or pure code. When we want to define a layout, the xml file is more convenient, because it is readable, reusable, and easy to replace compared with hard encoding. Therefore, in the following example, we will use the xml method (for more information about hard encoding rather than the xml method, see the AnimationSet class and the subclass of Animation ).
We can set attributes to determine when an animation will take place and its duration. Animation transformations can occur sequentially or simultaneously. For example, we can move a TextView from left to right, and then rotate it for 180 degrees, or we can make the moving and rotating animations happen at the same time. For each animation transform, you need to set your own attribute set (the start and end sizes must be set for the size change, the start and end angles must be set for the rotation change, and the rest must be similar ), you also need to set some common attributes, such as the start time and duration. If we want many transformations to happen together, set the same start time for them. If you want to change the sequence, you only need to set the start time to the duration of the previous animation.
To create an animation using an xml file, you must create an anim folder under the res directory of the project. The file must have only one root element, for example, <alpha>, <scale>, <translate>, <rotate>, interpolation element, or an <set> element contains these animation elements (or a set element ). If we want to make the animation order happen, for example, we set a separate startOffset attribute, just like the example below.
The following xml file comes from ApiDemo, which is used to scale and rotate a View object at the same time.
<set 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/decelerate_interpolator"> <scale android:fromXScale="1.4" android:toXScale="0.0" android:fromYScale="0.6" android:toYScale="0.0" android:pivotX="50%" android:pivotY="50%" android:startOffset="700" android:duration="400" android:fillBefore="false" /> <rotate android:fromDegrees="0" android:toDegrees="-45" android:toYScale="0.0" android:pivotX="50%" android:pivotY="50%" android:startOffset="700" android:duration="400" /> </set></set>
The coordinate system of the screen (0, 0) points above the upper left corner of the screen, the right is the x positive coordinate, down is the y positive coordinate.
Some values, such as ipvtx, can be specified to be related to itself or the parent class. Make sure that the format you use is the correct format for the desired effect. For example, 50% is 50% relative to, but 50 is different.
We can also specify an interpolator to determine how the transformation time changes. Android contains a few interpolation sub-classes, each of which has its own acceleration curve, such as accelerateInterpolator, it will tell the conversion speed to be slow at the beginning and then start to accelerate. We can set relevant attributes in xml.
If we call the above Code hyperspace_jump.xml, we use the following code to add an animation to an ImageView control.
ImageView spaceshipImage = (ImageView) findViewById(R.id.spaceshipImage);Animation hyperspaceJumpAnimation = AnimationUtils.loadAnimation(this, R.anim.hyperspace_jump);spaceshipImage.startAnimation(hyperspaceJumpAnimation);
As an optional method for startAnimatinon (), we can use Animation and setStartTime () to set the start time, and then use View and setAnimation () to set the Animation.
For more information about XML usage and optional tag attributes, see Animation Resources.
Note:
No matter whether your animation is moved or scaled down, the border of the View control with the animation is not automatically adjusted. Even so, the animation will still be drawn, if it exceeds the boundary in time, it will not be cut. However, if the animation exceeds the parent View range, the excess will be cut.
Address: http://developer.android.com/guide/topics/graphics/view-animation.html
An Android pen question: can a View be used to achieve an animated effect? How can this problem be achieved?
Use Animation. Look at this blog! Www.cnblogs.com/..6.html
An issue after android Animation changes the View position
Create a new user. That's all.