Android learning notes-java Implementation of tween animation

Source: Internet
Author: User

Android learning notes-java Implementation of tween animation
Android animations are divided into Tween animations and Frame animations. I recently learned about body tween animations. Now I will introduce my learning experiences and related knowledge as follows. Tween, also known as a compensation animation, allows you to zoom in, zoom in, rotate, or gradient objects. First, Tween animation has four main implementation classes: 1. AlphaAnimation: gradient (color) animation, which mainly controls transparency change animation. It is often constructed using AlphaAnimation (float fromAlpha, float toAlpha). fromAlpha: transparency at the beginning of the animation (value range: 0.0 to 1.0); toAlpha: transparency at the end of the animation; 2. ScaleAnimation: mainly controls the size change, often using ScaleAnimation (float fromX, float toX, float fromY, float toY, int should txtype, float should txvalue, int should tytype, float should tyvalue) to construct; fromX: scaling scale at the animation start X coordinate (relative to the size of the original image); toX: Scaling scale at the animation end X coordinate; fromY: scaling at the animation start Y coordinate ToY: The scaling scale on the Y coordinate of the Animation end; the scaling mode (type) on the X coordinate. The values are Animation. ABSOLUTE, Animation. RELATIVE_TO_SELF: relative to itself, Animation. RELATIVE_TO_PARENT; pivotXValue: the center position of the scaling on X coordinate; configurtytype: Scaling mode on Y coordinate. The values include Animation. ABSOLUTE, Animation. RELATIVE_TO_SELF, Animation. RELATIVE_TO_PARENT; equaltyvalue: Center Position of scaling on Y coordinate; 3. TranslateAnimation: Mainly used to control animation implementation class of position transformation. It is often used to translate eanimation (float fromXDelta, float toXDelta, float fromYDelta, Float toYDelta) to construct; fromXDelta: X coordinate of the animation start; toXDelta: X coordinate of the animation end; fromYDelta: Y coordinate of the animation start; toYDelta: Y coordinate of the animation end; 4. Rotate: mainly controls the animation implementation class of rotation. It is often constructed using RotateAnimation (float fromDegrees, float toDegrees, int rotate txtype, float rotate txvalue, int rotate tytype, float rotate tyvalue); fromDegrees: rotation start angle; toDegrees: rotation end angle; pivotXType, pivotXValue, pivotYType, and pivotYValue are similar to scaling animation ScaleAnimation; Second: included shared methods // set playing time animatio N. setDuration (2000); // set the number of repeat times, remembering the number of repeat animation. setRepeatCount (2); // set the duplicate mode. There are two RESTART Methods: re-start and REVERSE: Start animation in REVERSE order. setRepeatMode (AlphaAnimation. REVERSE); // start playback iv. startAnimation (animation); 3: instance, layout file we write like this, <LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android" xmlns: tools = "http://schemas.android.com/tools" android: layout_width = "match_parent" android: layout_height = "match_par Ent "android: orientation =" vertical "android: paddingBottom =" @ dimen/activity_vertical_margin "android: paddingLeft =" @ dimen/activity_horizontal_margin "android: paddingRight = "@ dimen/activity_horizontal_margin" android: paddingTop = "@ dimen/activity_vertical_margin" tools: context = "com. ftf. tween. mainActivity "> <LinearLayout android: layout_width =" fill_parent "android: layout_height =" wrap_content "android: ori Entation = "horizontal"> <Button android: onClick = "click" android: text = "Transparency" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: orientation = "horizontal"/> <Button android: onClick = "click2" android: text = "zoom" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: orientation = "horizontal"/> <Button android: onClick = "click3" android: text = "Rotate" andro Id: layout_width = "wrap_content" android: layout_height = "wrap_content" android: orientation = "horizontal"/> <Button android: onClick = "click4" android: text = "Translation" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: orientation = "horizontal"/> <Button android: onClick = "click5" android: text = "Combination" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: orie Ntation = "horizontal"/> </LinearLayout> <LinearLayout android: layout_width = "match_parent" android: layout_height = "match_parent" android: gravity = "center"> <ImageView android: id = "@ + id/iv" android: src = "@ drawable/ic_launcher" android: layout_width = "wrap_content" android: layout_height = "wrap_content"/> </LinearLayout> in the activity, write: // public void click (View view) {AlphaAnimation Animation = new AlphaAnimation (0.0f, 1.0f); animation. setDuration (2000); animation. setRepeatCount (2); animation. setRepeatMode (AlphaAnimation. REVERSE); iv. startAnimation (animation);} public void click2 (View view) {ScaleAnimation animation = new ScaleAnimation (0.2f, 2.0f, 0.2f, 2.0f, Animation. RELATIVE_TO_SELF, 0.5f, Animation. RELATIVE_TO_SELF, 0.5f); animation. setDuration (2000); animation. setRepe AtCount (2); animation. setRepeatMode (AlphaAnimation. REVERSE); iv. startAnimation (animation);} public void click3 (View view) {RotateAnimation animation = new RotateAnimation (0,360, Animation. RELATIVE_TO_SELF, 0.5f, Animation. RELATIVE_TO_SELF, 0.5f); animation. setDuration (2000); animation. setRepeatCount (2); animation. setRepeatMode (AlphaAnimation. REVERSE); iv. startAnimation (animation);} public void Click4 (View view) {TranslateAnimation animation = new TranslateAnimation (Animation. RELATIVE_TO_PARENT, 0.2f, Animation. RELATIVE_TO_PARENT, 1.0f, Animation. RELATIVE_TO_PARENT, 0.2f, Animation. RELATIVE_TO_PARENT, 1.0f); animation. setDuration (2000); animation. setRepeatCount (2); animation. setRepeatMode (AlphaAnimation. REVERSE); iv. startAnimation (animation);} public void click5 (View view) {// set the Mixed Mode, That is, put multiple playback effects together. AnimationSet set = new AnimationSet (false); TranslateAnimation pa = new TranslateAnimation (Animation. RELATIVE_TO_PARENT, 0.2f, Animation. RELATIVE_TO_PARENT, 1.0f, Animation. RELATIVE_TO_PARENT, 0.2f, Animation. RELATIVE_TO_PARENT, 1.0f); pa. setDuration (1, 2000); pa. setRepeatCount (2); pa. setRepeatMode (AlphaAnimation. REVERSE); RotateAnimation ra = new RotateAnimation (0,360, Animation. RELATIVE_TO_SELF, 0.5f, Animation. RELATIVE_TO_SELF, 0.5f); ra. setDuration (1, 2000); ra. setRepeatCount (2); ra. setRepeatMode (AlphaAnimation. REVERSE); ScaleAnimation sa = new ScaleAnimation (0.2f, 2.0f, 0.2f, 2.0f, Animation. RELATIVE_TO_SELF, 0.5f, Animation. RELATIVE_TO_SELF, 0.5f); sa. setDuration (1, 2000); sa. setRepeatCount (2); sa. setRepeatMode (AlphaAnimation. REVERSE); set. addAnimation (sa); set. addAnimation (ra); set. addAnimation (pa); iv. startAnimation (set );}

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.