1.设置布局文件在activity_main.xml修改
<?xml version="1.0" encoding="utf-8"?><android.support.constraint.ConstraintLayout xmlns:android=“http://schemas.android.com/apk/res/android”
xmlns:app=“http://schemas.android.com/apk/res-auto”
xmlns:tools=“http://schemas.android.com/tools”
android:layout_width=“match_parent”
android:layout_height=“match_parent”
tools:context=".MainActivity">
<Button
android:id="@+id/buttonSpin"
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:layout_marginStart=“8dp”
android:layout_marginLeft=“8dp”
android:layout_marginTop=“8dp”
android:layout_marginEnd=“8dp”
android:layout_marginRight=“8dp”
android:text=“单一动画”
app:layout_constraintEnd_toEndOf=“parent”
app:layout_constraintStart_toStartOf=“parent”
app:layout_constraintTop_toBottomOf="@+id/buttonValue" />
2.设置动画在MainActicity.java中修改
// 创建动画作用对象:此处以Button为例
private Button buttonSpin;
// 动画作用的对象的属性是旋转
objectAnimator4 = ObjectAnimator.ofFloat(imageView,“rotation”,0F,360F);
buttonSpin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
AnimatorSet animatorSet = new AnimatorSet();
//执行objectAnimator4
animatorSet.playSequentially(objectAnimator4);
// 设置动画运行的时长
animatorSet.setDuration(5000);
// 启动动画
animatorSet.start();
[](()效果图
[](()渐变
[](()实例说明:
1.设置布局文件在activity_main.xml修改
<?xml version="1.0" encoding="utf-8"?><android.support.constraint.ConstraintLayout xmlns:android=“http://schemas.android.com/apk/res/android”
xmlns:app=“http://schemas.android.com/apk/res-auto”
xmlns:tools=“http://schemas.android.com/tools”
android:layout_width=“match_parent”
andr