编程旋转绘制或视图 [英] Programmatically rotate drawable or view

查看:101
本文介绍了编程旋转绘制或视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/your_drawable"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="360" />

我想以编程方式旋转绘制。

I want programmatically rotate the drawable.

我应该怎么办呢?

下面是我的回调

private class RotateListener implements RotateGestureDetector.OnRotateGestureListener{
    @Override
    public boolean onRotate(MotionEvent event1, MotionEvent event2,
            double deltaAngle) {

        return true;
    }
}

deltaangle 不超过0.1,我不知道什么是获取价值。

The deltaangle not more than 0.1, I not sure what is the extract value.

推荐答案

以下code围绕其中心的ImageView的:

The following code rotates an ImageView around its center:

ImageView myImageView = (ImageView)findViewById(R.id.my_imageview);

AnimationSet animSet = new AnimationSet(true);
animSet.setInterpolator(new DecelerateInterpolator());
animSet.setFillAfter(true);
animSet.setFillEnabled(true);

final RotateAnimation animRotate = new RotateAnimation(0.0f, -90.0f,
    RotateAnimation.RELATIVE_TO_SELF, 0.5f, 
    RotateAnimation.RELATIVE_TO_SELF, 0.5f);

animRotate.setDuration(1500);
animRotate.setFillAfter(true);
animSet.addAnimation(animRotate);

myImageView.startAnimation(animSet);

这篇关于编程旋转绘制或视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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