Android 如何通过ObjectAnimator旋转可绘制对象?
将一件可拉深的作品制作成如下字母:Android 如何通过ObjectAnimator旋转可绘制对象?,android,rotation,drawable,objectanimator,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());
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);
}
但是,如果我想旋转一个像下面这样的可拉伸的,它不工作
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);
}
}
任何人都可以帮助我解决这个问题,或者这些是创建旋转可绘制动画的任何其他方法
很抱歉,我的英语很差。试试这个应用于图像的简单旋转动画
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);
这个答案只是为了回答问题,正确的是,可点击区域将不同于
视图
的当前位置。请检查此问题以确保可点击区域正确 尝试使用ObjectAnimator
ImageView imageview = (ImageView)findViewById(R.id.image);
ObjectAnimator imageViewObjectAnimator = ObjectAnimator.ofFloat(imageview ,
"rotation", 0f, 360f);
imageViewObjectAnimator.setDuration(1000); // miliseconds
imageViewObjectAnimator.start();
编辑
由于这个问题引起了一些注意,让我解释一下为什么要使用ObjectAnimator
而不是其他过渡动画师
使用ObjectAnimator
的一点是,如果您使用其他动画方法,例如过渡动画或其他一些动画,并且假设您想将按钮从屏幕左下角移动到左上角,它会同时移动项目的可见区域和可单击区域,它只会移动可见区域,而不会移动按钮本身,可单击区域仍将位于上一位置,在这种情况下,可单击区域仍将位于左下角,而不是移动按钮的左上角
如果对ObjectAnimator
执行相同操作,则可见区域和可单击区域都会将动画移动到所需位置。谢谢。但是我不想把绘图放到其他视图中,比如ImageView等等,而是想把它画在视图的一个子类上(不是ViewGroup)。@marine8888我想你错了,ImageView
只是view
的一个子类,而不是ViewGroup
(它本身就是view
的一个子类)。您可以创建自己的视图
子类,并在画布上呈现可绘制图像,但这与图像视图
的工作相同。我想通过触摸事件更改可绘制状态,可绘制图像是单个可绘制图像,而不是可绘制列表。例如,根据屏幕上的移动距离更改可绘制alpha值。这个功能已经完成了。然后,我想根据移动角度改变一个可拉伸方向。换句话说,根据角度旋转可拉伸部件。这些绘图将在同一视图上绘制。我想知道一个具有旋转属性的ObjectAnimator对象是否可以旋转一个可绘制的对象。也许,它可以旋转,因为imageview可以旋转用于背景可绘制的可绘制文件。可能是