如何通过 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 旋转可绘制对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Using Firebase Firestore in offline only mode(在仅脱机模式下使用Firebase FiRestore)
Crash on Google Play Pre-Launch Report: java.lang.NoSuchMethodError(Google Play发布前崩溃报告:java.lang.NoSuchMethodError)