mardi 12 juillet 2016

Android shape transformation of View

I wanna create transforming animation of the shape of View. For example changing rectangle to oval. I tried to do this in the same way with color animation:

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);

But when I tried to do it with ShapeDrawable[] I could no shaping transformation, but imageView became black.

 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);

So is there any programmatical way in Android to transform (change the shape of) View smoothly?

Aucun commentaire:

Enregistrer un commentaire