gpt4 book ai didi

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

转载 作者:IT老高 更新时间:2023-10-28 23:16:41 26 4
gpt4 key购买 nike

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

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,它就行不通了。

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);
}
}

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

对不起,我的英语不好。

最佳答案

尝试使用 ObjectAnimator

ImageView imageview = (ImageView)findViewById(R.id.image);

ObjectAnimator imageViewObjectAnimator = ObjectAnimator.ofFloat(imageview ,
"rotation", 0f, 360f);
imageViewObjectAnimator.setDuration(1000); // miliseconds
imageViewObjectAnimator.start();

编辑既然这个问题引起了人们的注意,让我解释一下为什么使用 ObjectAnimator 而不是其他的过渡动画师

使用 ObjectAnimator 的事情是,如果您使用其他动画方法,例如 Transition Animation 或其他一些 Animator,它会同时移动项目的可见区域和可点击区域,让我们说如果您想将 Button 从屏幕左下角移动到左上角,它只会移动可见区域而不是 Button 本身,可点击区域仍将位于上一个位置,在这种情况下,可点击区域仍将位于左下角,而不是您移动按钮的左上角。

如果您对 ObjectAnimator 执行相同操作,则可见区域和可点击区域都会移动到所需的位置。

关于android - 如何通过 ObjectAnimator 旋转可绘制对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14039265/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com