【问题标题】:What is Alternative of Animation drawable in Jetpack ComposeJetpack Compose 中可绘制动画的替代方法是什么
【发布时间】:2021-12-26 00:21:19
【问题描述】:

我正在尝试在 jetpack Compose 中实现帧动画。
我知道在android视图系统中,可以使用AnimationDrawable来实现。
但是在jetpack Compose中如何正确使用动画drawable类呢?

【问题讨论】:

标签: android kotlin android-layout android-jetpack-compose


【解决方案1】:

最后我找到了一个解决方案。我通过以编程方式创建可绘制动画并将其分配给 Image as Drawable,在 jetpack compose 中使用可绘制动画实现了帧动画。最后是使用动画可绘制引用来控制动画。我在下面发布示例代码...

val animationDrawable = AnimationDrawable()
//add your images in animationDrawable by giving information of duration etc like you gave in xml file..
Image(
    painter = rememberDrawablePainter(animationBlast),
    contentDescription = null,
    Modifier
        .offset {
            IntOffset(
                offsetX.toInt() - (if (size == 250) 300 else 0),
                offsetY.toInt() - (if (size == 250) 300 else 0)
            )
        }
        .size(size.dp), contentScale = ContentScale.Crop
)

animationDrawable?.start()

【讨论】:

  • 你能发布完整的代码示例吗?特别是您将图像添加到 AnimationDrawable 的部分
  • 确定我正在编辑它
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-07-08
  • 2021-10-19
  • 2020-08-04
  • 1970-01-01
相关资源
最近更新 更多