android - 同时在一个对象上使用相同的对象动画属性 (translationx) 两次
问题描述
我花了一整天的时间试图弄清楚这一点。我尝试了过多的代码组合,但没有一个想要工作。从技术上讲,它们确实有效,但不是我想要的方式。如果我添加 translationY 属性,它就可以工作。我基本上想同时在一个对象上运行 2 个动画,两个是translationx。对象应该在整个屏幕宽度上从左到右移动,并同时前后移动一小段距离。所以主要的问题是,是否有可能实现这一点,或者不能同时使用与 AnimatorSet 相同的属性?
这是我正在使用的当前代码:
private void _ballLevel20Animation () {
move1.cancel();
int center = (board.getMeasuredWidth() / 2);
int lr = board.getMeasuredWidth();
final float left = Float.valueOf(100 - center);
final float right = Float.valueOf(center - 100);
int center1 = (board.getMeasuredWidth() / 6);
final float left1 = Float.valueOf(100 - center);
final float right1 = Float.valueOf(center - 100);
move1.setTarget(ball);
move1.setPropertyName("translationX");
move1.setFloatValues(left, right);
move1.setRepeatCount(ObjectAnimator.INFINITE);
move1.setDuration((int)(ball_duration_increa));
move1.setRepeatMode(ValueAnimator.REVERSE);
bounce_ani.setTarget(ball);
bounce_ani.setPropertyName("translationX");
bounce_ani.setFloatValues((float)(SketchwareUtil.getDip(getApplicationContext(), (int)(-20))), (float)(SketchwareUtil.getDip(getApplicationContext(), (int)(20))));
bounce_ani.setRepeatCount(ObjectAnimator.INFINITE);
bounce_ani.setDuration((int)(ball_duration_increa / 6));
bounce_ani.setRepeatMode(ValueAnimator.REVERSE);
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.play(bounce_ani).with(move1);
animatorSet.start();
/*bounce_ani.setFloatValues(right1, left1);*/
}
解决方案
您可以尝试向动画添加动画侦听器。在监听器中,有 onAnimationEnd() 在动画完成时被调用。在这里,您可以调用后续动画,使它们看起来像是被链接的。
推荐阅读
- sql - 在 sql 文件末尾添加注释时出现 Liquibase 错误
- php - 致命错误:未捕获的异常 'Google\Service\Exception' 带有消息 '{ "error": "unauthorized_client", "error_description": "Unauthorized" }
- r - 根据包含参与者之间关系的数据框列更改边缘厚度
- spring - 具有单列的 EntityManager createQuery 引发类型错误
- java - Kotlin/java - 如何将日期时间字符串转换为 Instant?
- django - 在 Django admin 中注册 SQL 表
- node.js - 如何使用 Intuit-Oauth 节点库在 API 调用中传递访问令牌?
- java - 从 xml 到基于 Java 的配置的问题更改
- laravel - docker中的Laravel - browserSync设置问题
- python - 在不断变化的 Excel 中获取产品总和