旋转视图并在旋转时更新其内容

时间:2016-08-08 18:41:49

标签: android animation

我想将View旋转到90度并更新其内容并再次将其旋转到90度,到目前为止,我尝试了以下代码。

ObjectAnimator anim1 = (ObjectAnimator) AnimatorInflater.loadAnimator(getActivity().getApplicationContext(), R.animator.flip_animator);

                    anim1.setTarget(v);
                    anim1.setDuration(1000);
                    anim1.start();


ImageView box = (ImageView) v.findViewById(R.id.box);
        Bitmap bg = BoxUtils.getBoxBg(boxSize, boxMargin, Color.RED);
        box.setImageBitmap(bg);


                anim1.setTarget(v);
                anim1.setDuration(1000);
                anim1.start();

的xml:

<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
    android:valueFrom="0" android:valueTo="90" android:propertyName="rotationY" >
</objectAnimator>

然而它的工作却在下一个旋转90度之前改变了它的颜色,即使我在下一个旋转代码之前编写了更新代码。 有什么帮助吗?

1 个答案:

答案 0 :(得分:0)

问题是您的对象是从代码中异步旋转的。您已经设计了它,以便代码位于那里,而立方体进行第一次旋转,然后更改颜色。会发生的是代码启动动画,然后在立方体旋转时继续运行,这就是它提前改变颜色的原因。

以下动画视图的方法将添加一个结束动作,它将改变颜色然后旋转最后一个90:

View v;
v.animate()
.rotationY(90)
.setDuration(1000)
.withEndAction(new Runnable() {
  @Override
  public void run() {
    ImageView box = (ImageView) v.findViewById(R.id.box);
    Bitmap bg = BoxUtils.getBoxBg(boxSize, boxMargin, Color.RED);
    box.setImageBitmap(bg);

    v.animate().rotationY(90).setDuration(1000).start();
  }
}).start(); 
相关问题