我使用单个Animator实例来平滑地向下或向右滚动视图。首先,我在自定义View实现中使用公共参数对其进行设置:
private ObjectAnimator animator = new ObjectAnimator();
{
animator.setTarget(this);
animator.setDuration(moveDuration);
}然后我使用两种方法向下和向右移动
public void moveRight() {
if( animator.isRunning() ) animator.end();
animator.setPropertyName("scrollX");
animator.setIntValues(getScrollX(), getScrollX() + cellWidth);
animator.start();
}
public void moveDown() {
if( animator.isRunning() ) animator.end();
animator.setPropertyName("scrollY");
animator.setIntValues(getScrollY(), getScrollY() + cellHeight);
animator.start();
}我发现,只有第一次调用的方法才能正确工作。另一个错误,就像第一次运行的方法在动画对象中留下了一些痕迹。
如何删除这些痕迹和重新编程动画从右向下滚动,反之亦然?
发布于 2012-12-10 18:34:21
我也有这个问题。由于某些原因,第二次使用setPropertyName()似乎并不能清除之前的属性和/或值。
相反,使用setProperty()可以解决这个问题,例如:
Property<View, Float> mTranslationXProperty = Property.of(View.class,
Float.class, "translationX");
Property<View, Float> mScaleXProperty = Property.of(View.class,
Float.class, "scaleX");
...
animator.setProperty(mTranslationXProperty);
animator.setFloatValues(500f, 0f);
animator.start();
...
animator.setProperty(mScaleXProperty);
animator.setFloatValues(1f, 0f);
animator.start();发布于 2013-07-25 17:15:48
我可以使用下面的代码来重置值:
final AnimatorSet animate = (AnimatorSet) AnimatorInflater.loadAnimator(this, R.anim.anim_move);
List<Animator> animations = animate.getChildAnimations();
for (int i = 0; i < animations.size(); i++) {
ObjectAnimator animator = (ObjectAnimator) animations.get(i);
if (animator.getPropertyName().contentEquals("y")) {
animator.setFloatValues(0f, 500f);
}
}
animate.setTarget(starlightImageView);
animate.start();https://stackoverflow.com/questions/10630883
复制相似问题