我正在 Android 中创建购物应用程序。在我的应用程序中,我显示自定义列表视图中的项目列表。
如果客户选择一个项目,所选项目文本将从列表视图移动到购物车图像中。就像下图一样,
This type of animation is my requirement.
![enter image description here](https://i.stack.imgur.com/q2a8C.png)
但我的动画视图停在自定义行的末尾..就像这张图片一样。
![enter image description here](https://i.stack.imgur.com/QHYVp.png)
我的animation.xml代码,
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator"
android:fillAfter="true"
>
<translate
android:fromYDelta="0%p"
android:toYDelta="100%p"
android:fromXDelta="0%p"
android:toXDelta="100%p"
android:duration="1000"
/>
<alpha
android:duration="500"
android:fromAlpha="1.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:toAlpha="0.0" />
<scale
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="3500"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:toXScale="0.0"
android:toYScale="0.2" >
</scale>
</set>
Note:如果有人想要更多代码,我稍后发布..因为这个 qtn 已经需要更多的长度..
我的问题,
我的动画文本视图不能超出自定义行的范围。
那么如何将自定义行文本视图移动到图像的末尾(购物车图像)?
目标是将视图从一个位置动画到另一个位置,因此首先我们需要获取两个点。您可以执行以下操作:
int[] screenLocation = new int[2];
textView.getLocationOnScreen(screenLocation);
int startX = screenLocation[0];
int startY = screenLocation[1];
int[] screenLocationB = new int[2];
cartView.getLocationOnScreen(screenLocationB);
int endX = screenLocationB[0];
int endY = screenLocationB[1];
一旦您获得了文本视图的起始位置和希望其结束的位置(购物车视图的位置),我们就需要从一点到下一点进行动画处理。我们可以通过在窗口层或列表视图上方的框架布局上放置一个新的文本视图来做到这一点。
这里我们添加到窗口层:
WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
layoutParams.width = view.getMeasuredWidth();
layoutParams.height = view.getMeasuredHeight();
activity.addContentView(newTextView, layoutParams);
接下来我们设置起始位置。
newTextView.setTranslationX(startX);
newTextView.setTranslationY(startY);
最后我们制作动画。
newTextView.animate().setDuration(300)
.translationX(endX).translationY(endX).start()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)