补间动画
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/iv"
android:layout_centerInParent="true"
android:adjustViewBounds="true"
android:maxHeight="300dp"
android:maxWidth="300dp"
android:src="@drawable/one" />
</RelativeLayout>
MainActivity
package com.example.anim2;
import androidx.appcompat.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 MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView imageView = findViewById(R.id.iv);
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//通过加载xml动画设置文件来创建一个Animation对象
// Animation animation = AnimationUtils.loadAnimation(MainActivity.this,R.anim.alpha);
// Animation animation = AnimationUtils.loadAnimation(MainActivity.this,R.anim.rotate);
// Animation animation = AnimationUtils.loadAnimation(MainActivity.this,R.anim.scale);
Animation animation = AnimationUtils.loadAnimation(MainActivity.this,R.anim.translate);
imageView.startAnimation(animation);
}
});
}
}
alpha.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:fromAlpha="0"
android:toAlpha="1"
android:duration="2000"
/>
</set>
rotate.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate
android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:duration="2000"
/>
</set>
scale.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:fromXScale="1"
android:fromYScale="1"
android:toXScale="0.4"
android:toYScale="0.4"
android:pivotX="50%"
android:pivotY="50%"
/>
</set>
translate.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="0"
android:fromYDelta="0"
android:toXDelta="400"
android:toYDelta="400"
android:duration="2000"
>
</translate>
</set>