如何连续旋转图像? [英] how to rotate an image continuously?

查看:95
本文介绍了如何连续旋转图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用螺纹旋转该图像.我该怎么办?

I am trying to rotate this image by using a thread. what should I do?

     public class Start extends Activity {
        View base;
            Bitmap rotate, base1, rotate1;
        ImageView rotator;
        float angle, pivX, pivY;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.start);
            base = findViewById(R.id.base);
            rotator = (ImageView) findViewById(R.id.rotator);
            pivX = (rotator.getLeft()) / 2;
            pivY = (rotator.getTop()) / 2;
            Thread thread = new Thread() {
        @Override
        public void run() {
            for (angle = 0; angle < 50; angle++) {
                Matrix matrix = new Matrix();
                rotator.setScaleType(ScaleType.MATRIX); // required
                matrix.postRotate((float) angle, pivX, pivY);
                rotator.setImageMatrix(matrix);
                if (angle == 40) {`enter code here`
                    angle = 0;
                    return;
                }
            }
        }
    };

    thread.start();

        }
    }

推荐答案

使用此代码旋转按钮

btn_rotate = (Button)findViewById(R.id.btn_rotate);
rotation = AnimationUtils.loadAnimation(MainActivity.this, R.anim.rotate);
rotation.setFillAfter(true);
btn_rotate.startAnimation(rotation);

rotate.xml

将此文件放入res-> anim-> rotate.xml

rotate.xml

put this file in res->anim->rotate.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >

<rotate
    android:duration="500"
    android:fromDegrees="0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:repeatCount="infinite"
    android:startOffset="0"
    android:toDegrees="360" />
</set>

这篇关于如何连续旋转图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆