如何在Android中创建“添加到购物车”动画? [英] How to create an 'add to cart' animation in android?

查看:73
本文介绍了如何在Android中创建“添加到购物车”动画?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用看起来像这样( https://dribbble.com/shots/ 2189587-添加到购物车)

My app looks somewhat like this (https://dribbble.com/shots/2189587-Add-to-cart)

我想类似地将产品快照移到下面的购物车中。我以前从未接触过动画,因此我要花点时间来理解这一点。

I want to similarly move a snapshot of the product into the cart below. I have never worked with animations before so I'm struggling a little bit to understand this.

为得到答案,假定产品图像位于ImageView中,而购物车按钮是右下角的浮动操作按钮。

For your answer, assume that the product image is in an ImageView and the cart button is a floating action button in the bottom right.

该页面的代码在这里:

预先感谢!

推荐答案

从理论上讲,我会尝试以下方式:

Theoretically, I would try somethink like:


  1. 具有2个ImageView:一个位于RecyclerView中,另一个位于与FAB相同的层次结构级别(在xml布局中)。隐藏第二个。

  1. Have 2 ImageView: one in your RecyclerView and one at the same hierarchy level than the FAB (in the xml layout). Hide the second one.

单击产品时,将单击的图像的位图复制到第二个ImageView中

When the product is clicked, copy the bitmap of your clicked image into the second ImageView

相对于FAB容器检索产品图像的X和Y-递归在其父视图中获取视图的getX和getY,直到您位于父视图中(不要忘记在RecyclerView中删除scrollX和scrollY )

Retrieve the X and Y of your product image relative to your FAB container -- recursively getX and getY of your view in its parent until you're in the parent (don't forget to remove the scrollX and scrollY in the RecyclerView)

将第二张图像放置到检索到的X和Y位置

Place your second image to the X and Y retrieved

为您的图片等待要布局的图像(getViewTreeObserver()。addOnPredrawListener()),然后应用动画将其移动到FAB的中心。您将需要按比例缩小图像并进行转换(让FAB的x和y知道您的目的地)

Wait for your image to be layout (getViewTreeObserver().addOnPredrawListener()) and apply the animation to move it to the center of the FAB. You will need to scale down the image and translate it (get the x and y of the FAB to know your destination)

添加一个onAnimationEndListener,显示+在FAB顶部的1

Add a onAnimationEndListener which display the +1 on top of the FAB

将向下转换动画应用于+1视图(+1将绘制在FAB顶部,但由于图标,而+1是白色的,应该没问题)

Apply a down translation animation to the +1 view (the +1 will be drawn on top of the FAB but since the icon and the +1 are white, it should be fine)

祝您好运,工作量很大!

Good luck, that's a fair amount of work!

这篇关于如何在Android中创建“添加到购物车”动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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