mar*_*888 18 android rotation drawable objectanimator
像这样对待一个可绘制的工作:
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);
}
Run Code Online (Sandbox Code Playgroud)
但是,如果我想像下面那样旋转一个抽屉,它就不起作用了.
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);
}
}
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮我解决这个问题,或者这是创建旋转可绘制动画的任何其他方法.
我很遗憾我的英语不好.
Nas*_*kov 62
试着ObjectAnimator改为.
ImageView imageview = (ImageView)findViewById(R.id.image);
ObjectAnimator imageViewObjectAnimator = ObjectAnimator.ofFloat(imageview ,
"rotation", 0f, 360f);
imageViewObjectAnimator.setDuration(1000); // miliseconds
imageViewObjectAnimator.start();
Run Code Online (Sandbox Code Playgroud)
编辑
因为这个问题吸引了一些注意力让我解释为什么要使用ObjectAnimator而不是其他过渡动画师
关于使用的事情ObjectAnimator是它正在移动项目的可见区域和可点击区域,如果你使用另一种动画方法,例如Transition Animation或其他一些Animators,让我们说如果你想Button从左下角移动它屏幕向左上方,它只会移动可见区域而不是Button自身,可点击区域仍然在前一个位置,在这种情况下,可点击区域仍然位于左下角而不是左上角按钮.
如果您执行相同操作ObjectAnimator,则可见区域和可单击区域将移动所需位置.
Rah*_*hul 18
尝试将这种简单的旋转动画应用于图像.
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);
Run Code Online (Sandbox Code Playgroud)
这个答案只是为了问题,可点击区域View与当前位置不同是正确的.请检查此问题以使可点击区域正确无误.TranslateAnimation后无法点击按钮
| 归档时间: |
|
| 查看次数: |
31735 次 |
| 最近记录: |