Android View 的变形

标签 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

最佳答案

您可能想尝试 android.view.ViewAnimationUtils,但它只适用于 api 19 以上。

Example

关于Android View 的变形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37887526/

相关文章:

java - 无法解析 Android 中的符号

Android翻盖动画和ease up(翻书动画)

android - 没有调用 start 的 ViewPropertyAnimator,有区别吗?

iphone - Objective-C CALayer UIView 真实旋转

python - Pandas 根据列值复制行

opengl - 相对于指定空间正确转换节点?

android - 与服务提供商的通信失败 : Twitter

android - android 中的自定义字体(适用于整个应用程序)

棉花糖或更高版本的窗口类型 2010 的 Android 权限被拒绝

android - 使用 ObjectAnimator 淡出并翻译 VectorDrawable