如何通过 ObjectAnimator 旋转可绘制对象?

How to rotate a drawable by ObjectAnimator?(如何通过 ObjectAnimator 旋转可绘制对象?)

本文介绍了如何通过 ObjectAnimator 旋转可绘制对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

像这样很好地绘制一个可绘制的作品:

Alphaing a drawable work well like this:

if(mAlphaAnimation == null){
        mAlphaAnimation = ObjectAnimator.ofFloat(this, "alpha", 0.0f,1.0f).setDuration(TARGET_ANIM_ALPHA_DURATION);
        mAlphaAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
        mAlphaAnimation.setStartDelay(TARGET_ANIM_ALPHA_DELAY_BASE*power);
        mAlphaAnimation.setRepeatCount(ValueAnimator.INFINITE);
        mAlphaAnimation.setRepeatMode(ValueAnimator.REVERSE);
        mAlphaAnimation.addUpdateListener(this);
 }

但是如果我想像下面那样旋转一个drawable,它就行不通了.

But if I want rotate a drawable like below , it don's work.

private void createRotateAnim(float fromDegress,float toDegress,int duration){
    if(mRotateAnimation == null){
        mRotateAnimation = ObjectAnimator.ofFloat(this, "rotation",fromDegress,toDegress).setDuration(duration);
        mRotateAnimation.setStartDelay(100);
        mRotateAnimation.setInterpolator(new AccelerateInterpolator());
        mRotateAnimation.addUpdateListener(this);
    }
}

任何人都可以帮我解决这个问题,或者这些是创建旋转可绘制动画的任何其他方式.

Anyone can help me to fix this issue, or these is any other way to create a rotation drawable animation .

对不起,我的英语不好.

I am sorry to my poor English.

推荐答案

试试这个简单的旋转动画应用于图像.

Try this simple Rotation Animation applied to a image.

 ImageView imageview = (ImageView)findViewById(R.id.myimage);
 RotateAnimation rotate = new RotateAnimation(180, 360, Animation.RELATIVE_TO_SELF,    
 0.5f,  Animation.RELATIVE_TO_SELF, 0.5f);
  rotate.setDuration(500);
 imageview.startAnimation(rotate);

这个答案只是为了提问,可点击区域与View的当前位置不同是正确的.请检查此问题以使可点击区域正确.按钮在 TranslateAnimation 后不可点击

This answer is just for a sake of question, it is correct that Clickable area will be different than View's current position. Please check this question for making clickable area correct. Button is not clickable after TranslateAnimation

这篇关于如何通过 ObjectAnimator 旋转可绘制对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何通过 ObjectAnimator 旋转可绘制对象?

基础教程推荐