安卓旋转动画

布局

<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">


    <ImageView
        android:id="@+id/imageView"
        android:layout_width="89dp"
        android:layout_height="93dp"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
    app:srcCompat="@mipmap/asd"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
         />


    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="94dp"
        android:layout_height="68dp"
        app:srcCompat="@drawable/wasd"
        app:layout_constraintCircleRadius="120dp"
        app:layout_constraintCircleAngle="30"
        app:layout_constraintCircle="@id/imageView" />


    <ImageView
        android:id="@+id/imageView3"
        android:layout_width="79dp"
        android:layout_height="90dp"
        app:srcCompat="@drawable/sqyas"
        app:layout_constraintCircleRadius="120dp"
        app:layout_constraintCircleAngle="130"
        app:layout_constraintCircle="@id/imageView2" />
</android.support.constraint.ConstraintLayout>

java代码

 private ImageView mimageView1;
    private ImageView mimageView2;
    private ImageView mimageView3;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setTheme(R.style.AppTheme1);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        initData(mimageView2, 5000);
        initData(mimageView3, 5000);
        RotateAnimation rotateAnimation = (RotateAnimation) AnimationUtils.loadAnimation(this,R.anim.anim);
        mimageView1.startAnimation(rotateAnimation);

    }

    public void initView() {
        mimageView1 = findViewById(R.id.imageView);
        mimageView2 = findViewById(R.id.imageView2);
        mimageView3 = findViewById(R.id.imageView3);
    }

    public void initData(final ImageView button, long duration) {
        final ConstraintLayout.LayoutParams params = (ConstraintLayout.LayoutParams) button.getLayoutParams();
        final ValueAnimator animator = ValueAnimator.ofFloat(params.circleAngle, params.circleAngle + 360);
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                params.circleAngle = (Float) animator.getAnimatedValue();
                button.setLayoutParams(params);
            }
        });
        animator.setDuration(duration);
        animator.setInterpolator(new LinearInterpolator());
        animator.setRepeatCount(ValueAnimator.INFINITE);
        animator.start();
    }

}
发布了15 篇原创文章 · 获赞 7 · 访问量 1万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 精致技术 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览