如何仅将android布局动画应用于特定索引以上的子项?
我有一个包含一系列注释的 ListView。
目前,当列表首次加载时,我使用布局动画将所有笔记从侧面滑入;这很有效。
但是,我试图弄清楚如何仅将布局动画应用于列出低于某一点的项目。假设我删除了列表中的一个项目:我希望将其下方的所有项目向上移动到已删除笔记的旧位置。
我尝试找到一种通过子索引自定义动画延迟或插值器的方法,但没有找到适合此位置的任何内容。有没有办法使用自定义布局动画(例如扩展 LayoutAnimationController)来执行此操作,或者我必须执行此低级别操作并单独为每个视图设置动画?
有什么建议吗?
I have a ListView containing a series of notes.
Currently I use a layout animation to slide all the notes in from the side when the list first loads; this works perfectly.
However, I'm trying to figure out how to apply a layout animation only to list items below a certain point. Say I delete an item on the list: I'd like all items below it to shift up into the deleted note's old spot.
I've tried finding a way to customize the animation delays or interpolators by child index but haven't found anything appropriate for this location. Is there a way to do this using a custom layout animation (such as extending LayoutAnimationController) or would I have to do this low level and animate each view individually?
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
创建动画并在列表中调用它
OnItemClickListener
。之后,您可以使用适配器的notifyDataSetChanged
刷新列表内容。在此示例中,我创建了一个名为
removeListItem
的方法,该方法接收要删除的行以及该行在列表内容数组中的位置。Create your animation and call it in your list
OnItemClickListener
. After that you might use the adapter'snotifyDataSetChanged
to refresh the list content.In this example, I created a method called
removeListItem
with receives the row you want to remove and the position of that row in you list content array.我遇到了一个非常类似的问题,并且能够找到一个带有简单
View
子类的解决方案,该子类允许您使用布局动画控制器仅对您指定的视图进行动画处理。请参阅此链接:LayoutAnimationController 能否仅对指定视图进行动画处理
I had a very similar problem and was able to find a solution with a simple
View
subclass that allows you to use a layout animation controller to animate only the views that you specify. Please see this link:Can LayoutAnimationController animate only specified Views
在布局 xml 中,尝试添加:
这将自动为列表视图中的插入和删除设置动画。
如果您有名为 anim_translate_left 的自定义动画,请改用:
来源:Google API
In your layout xml, try adding:
This will automatically animate insertions and deletions from your listview.
If you have a custom animation, named anim_translate_left, use instead:
Source: Google API's