实现效果:
首先在res文件夹下新建一个文件anim下在新建两个XML文件
<?xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXScale="100%"
android:toXScale="10%"
android:fromYScale="100%"
android:toYScale="10%"
android:pivotY="50%"
android:pivotX="50%"
android:duration="1000"></scale>
<?xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXScale="10%"
android:toXScale="100%"
android:fromYScale="10%"
android:toYScale="100%"
android:pivotY="50%"
android:pivotX="50%"
android:duration="1000"></scale>
package com.example.g160628_android_17_animation;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
public class Main2Activity extends AppCompatActivity {
private ImageView main_image2;
private Animation animation1;
private Animation animation2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
main_image2 = (ImageView) findViewById(R.id.main_image2);
}
public void operation2(View view){
switch (view.getId()){
case R.id.but_main_scale2:
//点击事件时图片先缩小
animation1 = AnimationUtils.loadAnimation(this, R.anim.iv_scale);
main_image2.startAnimation(animation1);
animation2 = AnimationUtils.loadAnimation(this, R.anim.iv_scale2);
//设置监听事件
animation1.setAnimationListener(new Animation.AnimationListener() {
//动画开始调用
@Override
public void onAnimationStart(Animation animation) {
}
//动画结束时调用
@Override
public void onAnimationEnd(Animation animation) {
main_image2.startAnimation(animation2);
}
//动画重复时调用
@Override
public void onAnimationRepeat(Animation animation) {
}
});
//设置监听事件
animation2.setAnimationListener(new Animation.AnimationListener() {
//动画开始调用
@Override
public void onAnimationStart(Animation animation) {
}
//动画结束时调用
@Override
public void onAnimationEnd(Animation animation) {
main_image2.startAnimation(animation1);
}
//动画重复时调用
@Override
public void onAnimationRepeat(Animation animation) {
}
});
break;
}
}
}