Android Scaleanimation class: Dimensional change Animation class

Source: Internet
Author: User

Android JDK provides us with 4 animation effects, namely: Alphaanimation,rotateanimation, Scaleanimation, Translateanimation. Today I would like to explain the animation effect of translateanimation. I was also in the animation of a mobile image of the project, encountered some problems. On the internet to check a lot of information, for several days. Finally understand how to use this translateanimation, recorded in this article, so that later forgotten can be consulted.

http://gundumw100.iteye.com/category/156622

9.4 Scaleanimation class: Dimensional change Animation class

The Scaleanimation class is an animated class of dimensional changes in an Android system that controls the size change of a View object that inherits from the animation class. Many of the methods in the Scaleanimation class are consistent with the animation class, and the most common method in this class is the Scaleanimation construction method.

"Basic Syntax" public scaleanimation (float FromX, float toX, float fromY, float toY, int pivotxtype, float pivotxvalue, int pivoty Type, float Pivotyvalue)

Parameter description

FromX: The scaling dimension on the starting X coordinate.

ToX: Ends the Scaling dimension on the x-coordinate.

FromY: The scaling dimension on the starting y-coordinate.

ToY: Ends the scaling dimensions on the y-coordinate.

Pivotxtype:x axis of the scaling mode, you can take the value of absolute, relative_to_self, relative_to_parent.

The scaling value of the pivotxvalue:x coordinates.

Pivotytype:y axis of the scaling mode, you can take the value of absolute, relative_to_self, relative_to_parent.

The scaling value of the pivotyvalue:y coordinates.

The example below demonstrates how to set a simple dimensional change animation effect by using code.

  1. public class Firstactivity extends Activity {
  2. /** called when the activity is first created. */
  3. @Override
  4. public void OnCreate (Bundle savedinstancestate) {//overloaded OnCreate method
  5. Super.oncreate (savedinstancestate);
  6. Setcontentview (R.layout.main);
  7. Final ImageView image= (ImageView) Findviewbyid (r.id.imageview1);//imageview Object
  8. Button btn1= (button) Findviewbyid (R.id.button1); Button Object
  9. Button btn2= (button) Findviewbyid (R.id.button2);
  10. Final Animation scaleanimation= new
  11. Scaleanimation (0f,1f,0f,1f,animation.relative_to_self,0.5f,animation.relative_to_self,0.5f);
  12. Set the size Change animation object
  13. Btn1.setonclicklistener (New View.onclicklistener () {//Set listener
  14. @Override
  15. public void OnClick (View v) {
  16. TODO auto-generated Method Stub
  17. Scaleanimation.setduration (2000); Animation duration
  18. Image.setanimation (scaleanimation); Set animation
  19. Scaleanimation.startnow (); Start animation
  20. }
  21. });
  22. Btn2.setonclicklistener (New View.onclicklistener () {//Set listener
  23. @Override
  24. public void OnClick (View v) {
  25. TODO auto-generated Method Stub
  26. Scaleanimation.cancel (); Cancel Animation execution
  27. }
  28. });
  29. }
  30. }

In this code, you first create an animated object with a dimension change by Scaleanimation construction method. Then, the duration of the animation is set in the first button listener, and then the animation is started. Cancels the animation in a second button listener. The reader runs this code and will see the picture gradually changing from small to large, as shown in 9.9. Finally, the picture is increased to the original size when it stops, as shown in 9.10.

Figure 9.9 Dimensional Change animation
Figure 9.10 Original Size picture

 

The translateanimation is a moving animation effect. It has three constructors, namely:

1.public translateanimation (Context context,attributeset attrs) Skip

2.public translateanimation (float fromxdelta, float toxdelta, float fromydelta, float toydelta)

This is one of our most common construction methods,

Float Fromxdelta: This parameter represents the difference between the point at which the animation starts and the current view x coordinate;

Float Toxdelta, which represents the difference between the point at which the animation ends and the current view x coordinate;

Float Fromydelta, which represents the difference between the starting point of the animation and the current view y-coordinate;

float Toydelta) This parameter represents the difference between the point at which the animation starts and the current view y-coordinate;

If the view is in a (x, y) point then the animation is moved from point B (X+fromxdelta, Y+fromydelta) to point C (X+toxdelta,y+toydelta).

3.Public translateanimation (int fromxtype, float fromxvalue, int toxtype, float toxvalue, int fromytype, Flo At Fromyvalue, int toytype, float toyvalue)

Fromxtype: The first parameter is a reference to the value in the x-axis direction (Animation.absolute, Animation.relative_to_self,or animation.relative_to_parent);

Fromxvalue: The second parameter is the starting value of the first parameter type;

Toxtype,toxvalue: The third parameter and the fourth parameter are the end references and corresponding values in the x-axis direction;

The following four parameters are not explained. If you select Animation.absolute all, it is actually the second constructor.

Take the x-axis as an example to describe the relationship between references and corresponding values:

If the selection reference is Animation.absolute, then the corresponding value should be a specific coordinate value, such as 100 to 300, which refers to absolute screen pixel units

If the selection reference is animation.relative_to_self or animation.relative_to_parent refers to a relative to itself or to a parent control, the corresponding value should be interpreted as relative to itself or the number of times or percent of the parent control. The multi-test parameter is clear.

Android Scaleanimation class: Dimensional change Animation class

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.