视图

时间:2016-06-17 17:53:05

标签: android android-animation transformation

我想创建View形状的变换动画。例如,将rectangle更改为oval。我试着用彩色动画做同样的事情:

ColorDrawable[] color = {new ColorDrawable(Color.RED), new ColorDrawable(Color.BLUE), new ColorDrawable(Color.RED)};
TransitionDrawable drawable = new TransitionDrawable(color);
    drawable.startTransition(1000);
    image.setBackground(drawable);

但是当我尝试使用ShapeDrawable[]时,我无法塑造转型,但imageView变黑了。

 float[] outerR = new float[] {4, 4, 4, 4, 4, 4, 4, 4};
    ShapeDrawable oval = new ShapeDrawable(new OvalShape());
    ShapeDrawable rect = new ShapeDrawable(new RoundRectShape(outerR, null, null));
    rect.setBounds(0,0,120,120);
    oval.setBounds(0,0,120,120);
    ShapeDrawable [] draws = {rect, oval};

    TransitionDrawable drawable = new TransitionDrawable(draws);
    drawable.startTransition(1000);
    image.setBackground(drawable);

那么在Android中有任何编程方式可以顺利转换(更改View的形状吗?

1 个答案:

答案 0 :(得分:1)

你可能想尝试android.view.ViewAnimationUtils但它只能在api 19之上运行。

Example