如何在 Jetpack Compose Android 上的 LazyColumn 中显示项目视图的动画 [英] How to show animate an item view in LazyColumn on Jetpack Compose Android

查看:72
本文介绍了如何在 Jetpack Compose Android 上的 LazyColumn 中显示项目视图的动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在惰性列视图中有一个项目列表.

I have a list of items in lazy column view.

当我们从列表中删除一项时,我们如何显示动画.

How we can show animation when we are removing the one item from the list.

我需要为被删除的视图设置动画.删除操作是通过按下视图内的删除图标来完成的.

I need to animate the view which is getting deleted. The delete operation is done by pressing the delete icon inside the view.

我尝试了 AnimationVisibility,但没有按预期工作.

I Tried with AnimationVisibility and its not working as expected.

推荐答案

它还没有得到官方支持,但他们正在努力.您可能可以实现它,但方式很笨拙.

It is not officially supported yet but they are working on it. You can probably achieve it but in a hacky way.

当你的列表更新时,你的组合被重新创建,它还不支持项目的动画,所以你必须在你的项目上添加一个布尔变量并在它被删除"时更改值.而不是从列表中删除它.显示更新后的列表后,您可以为要移除的项目设置动画并延迟,然后在动画结束后更新列表.

When your list updates, your composable is recreated and it doesn't support animations for items yet, so you have to add a boolean variable on your item and change the value when it's "deleted" instead of removing it from the list. Once the updated list is shown, you can animate the item being removed with a delay and then update the list without it once the animation is over.

我没有亲自测试过这种方法,所以它可能无法按预期工作,但这是我能想到的不支持更新动画的惰性列表的唯一方法.

I have not personally tested this method so it might not work as expected but that's the only way I can think of with lazy lists not supporting update animations.

这篇关于如何在 Jetpack Compose Android 上的 LazyColumn 中显示项目视图的动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆