android -> size change animation class (ScaleAnimation)

Reference: https://my.oschina.net/u/242041/blog/198971

 

【基本语法】public ScaleAnimation (float fromX, float toX, float fromY, float toY, int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)

Parameter Description

fromX: The scaling size on the starting X coordinate. (1f can be regarded as 100% width)

toX: End the scaling size on the X coordinate. ( 0f can be seen as 0% width) 

fromY: The scaling size on the starting Y coordinate. (1f can be regarded as 100% height)

toY: End the scaling size on the Y coordinate. (0f can be regarded as 0% height)

pivotXType: The scaling mode of the X axis, which can be ABSOLUTE, RELATIVE_TO_SELF, RELATIVE_TO_PARENT.

pivotXValue: The scaling value of the X coordinate. (It can be understood that the value of the end position 1f = 100% has the last edge, and 0f=0% is the leftmost) 

pivotYType: The scaling mode of the Y axis, which can be ABSOLUTE, RELATIVE_TO_SELF, RELATIVE_TO_PARENT.

pivotYValue: The scaling value of the Y coordinate. ( 1f=100% bottom, 0f=0% top) 

[Example demonstration] The following code demonstrates how to set a simple size change animation effect.

 

public class firstActivity extends Activity {  
/** Called when the activity is first created. */  
@Override  
public void onCreate(Bundle savedInstanceState) {           //重载onCreate方法  
    super.onCreate (savedInstanceState);  
    setContentView(R.layout.main);  
 
    final ImageView image=(ImageView)findViewById(R.id.imageView1); //ImageView对象  
    Button btn1=(Button)findViewById(R.id.button1); //Button object  
    Button btn2=(Button)findViewById(R.id.button2);  
    final Animation scaleAnimation= new   
     ScaleAnimation(0f,1f,0f,1f,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);  
                                                        //Set the size change animation object  
    btn1.setOnClickListener(new View.OnClickListener() { //Set the listener  
          
        @Override  
        public void onClick(View v) {  
            // TODO Auto-generated method stub  
            scaleAnimation.setDuration(2000); //Duration of animation  
            image.setAnimation(scaleAnimation); //Set animation  
            scaleAnimation.startNow(); //Start animation  
        }  
    });  
    btn2.setOnClickListener(new View.OnClickListener() { //Set the listener  
          
        @Override  
        public void onClick(View v) {  
            // TODO Auto-generated method stub  
            scaleAnimation.cancel(); //Cancel animation execution  
        }  
    });  
}  
}

 

 Also available at 

scaleAnimation.startNow();
XXX.setVisibility(View.GONE);

Then set setVisibility(View.GONE) or VISIBLE to indicate whether you want the element to be displayed or hidden.

 

image.clearAnimation() clear animation effect

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326289310&siteId=291194637