本文介绍了如何实现自定义列表视图文字动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创造了android的购物应用程序。在我的应用程序,我将展示从自定义列表视图中的项目清单。

I am creating shopping application in android. In my app, I show list of items from custom list view.

如果用户选择一个项目,从列表视图中选择的项目文本移动到购物车的形象。像下面的图片,

If customer select an item, Selected item text moves from listview into shopping cart image. Like below image,

此类型的动画是我的要求。

This type of animation is my requirement.

但是我的动画视图停在自定义行的结尾......这样的形象。

我animation.xml code,

<?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>

注意::如果有人想了解更多code我以后的文章..因为这已经QTN需要更多的长度。

Note: If anybody want more code I post later.. because already this qtn take more length..

我的问题,

我的动画的TextView不能超过绑定自定义行的。

My animated textview cannot exceeds bound of custom row.

所以如何将自定义行的TextView到图像(购物车图像)的结束?

so How to move custom row textview into end of the image(Shopping cart image)?

推荐答案

我们的目标是从一个位置视图动画到另一个位置,所以我们首先需要拿到两分。你可以做到以下几点:

The goal is to animate the view from one location to another location so first we need to get the two points. You can do the following:

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];

一旦你的TextView中双方的起始位置,你希望它结束​​时(该cartview的位置)的位置,我们需要一分二的下一个动画。我们可以通过将一个新的TextView在任一窗口层以上的ListView中的FrameLayout做到这一点。

Once you have both the starting location of the textview and the location you want it to end at (location of the cartview), we need to animate from one point two the next. We can do this by placing a NEW textview on either the window layer or a framelayout above your listview.

下面我们添加到窗口层:

Here we add to the window layer:

WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
layoutParams.width = view.getMeasuredWidth();
layoutParams.height = view.getMeasuredHeight();
activity.addContentView(newTextView, layoutParams);

接下来我们设置的起始位置。

Next we set the starting position.

 newTextView.setTranslationX(startX);
 newTextView.setTranslationY(startY);

最后,我们的动画。

Finally we animate.

 newTextView.animate().setDuration(300)
       .translationX(endX).translationY(endX).start()

这篇关于如何实现自定义列表视图文字动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-18 16:14
查看更多