如何在线性布局中添加动画?
我正在使用线性布局从 .net 服务器获取带有图像的消息。
当新消息到来时,布局的位置增加,新消息被一条一条地添加到布局的顶部。
问题是当新消息到来时,新消息突然添加到布局中。
我想将动画应用到布局,并使我的应用程序就像新消息出现时消息会慢慢添加到布局中一样。意味着之前的消息缓慢向下移动,新消息添加到布局的顶部。
I am using linear layout to get the message with image from .net server.
when the new message is come the position of the layout is increased and the new message is added to the top of the layout one by one.
the problem is when the new message will come,the new message is added to layout suddenly.
I want to apply animation to the layout and make my app like when the new message is come the message is added to the layout slowly. means the previous messages move down slowly and new message is added top of the layout.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在应保存数据的 LinearLayout 上使用 android:animateLayoutChanges。添加新内容时这将触发动画。首先将旧数据下移,为更多内容腾出空间。然后是第二步,新数据将淡出到可用空间中。
示例代码
main.xml
basicanimation.java
Use android:animateLayoutChanges on the LinearLayout that shall hold the data. This will trigger an animation when adding new content. It starts by moving the old data down making room for more content. Then follows a second step where the new data will fade into the free space.
Example code
main.xml
basicanimation.java