问题描述
我正在跟踪Android official documentation,专门尝试将View
沿着随机路径从随机起始X移至随机结束Y,然后从最后一个位置无限地移动Path
(完全随机地x和y,但沿路径!-animation-)。
我认为最好的选择是使用ObjectAnimator
属性作为View
的参数,至少设法制作曲线动画,然后以某种随机性从那里移动。
它会产生奇怪的运动,例如在View
内应用比例尺和度量,例如作用于视图的边缘并保持中心恒定,这是我不希望的,我想移动{{1 }},就像在屏幕上一样。
我的代码:
AnimatorSet animatorSet = new AnimatorSet();
PathInterpolator pathInterpolator = null;
Path path = null;
ObjectAnimator objectAnimator = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
path = new Path();
path.arcTo(0f,0f,100f,270f,-180f,false);
objectAnimator = ObjectAnimator.ofFloat(headView,ImageView.SCALE_X,ImageView.SCALE_Y,path);
objectAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
objectAnimator.setRepeatCount(5);
objectAnimator.setDuration(2000);
}
animatorSet.playTogether(
objectAnimator
);
animatorSet.start();
另外,当我尝试定义Path
和PathInterpolator
时,它会崩溃,但可能是另外一回事了,我不需要。
我的目标是解决这个问题,使其能够继续增加随机性。
编辑1:
我认为ofFloat
参数不正确,我尝试了View.X,View.Y
,但很遗憾,View完全消失了。而且我也尝试过:ImageView.scale / translation / x / rotation
。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)