ListView动画单个项目

Bas*_*der 13 animation android listview

我有一个带有项目的ListView.当用户单击某个项目时,它的高度应该缩放为零,并且下面的所有项目都应向上滚动.我下面的代码不起作用.使用我的代码,点击的项目向右缩放,但下面的项目不向上滚动,它们保持在相同的位置.我也尝试过使用LinearLayout但是存在同样的问题.

有一个应用程序可以做到这一点.它叫做任务.

这个小图片应该解释这个问题

我目前的实现如下:

@Override
public void onItemClick(AdapterView<?> arg0, View v, final int index,
        long id) {
    Animation anim = AnimationUtils.loadAnimation(getActivity(),
            R.anim.scaleup);
    v.startAnimation(anim);
}
Run Code Online (Sandbox Code Playgroud)

<set android:shareInterpolator="false" >
    <scale
        android:duration="700"
        android:fillAfter="false"
        android:fillBefore="false"
        android:fromXScale="1.0"
        android:fromYScale="1.0"
        android:interpolator="@android:anim/accelerate_decelerate_interpolator"
        android:pivotY="0%"
        android:toXScale="1.0"
        android:toYScale="0.0" />
</set>
Run Code Online (Sandbox Code Playgroud)

小智 7

这是我制作的一个类(从我在这里找到的源代码修改)可以为您提供所需的功能.

public class FadeUpAnimation extends Animation {

int mFromHeight;
View mView;

public FadeUpAnimation(View view) {
    this.mView = view;
    this.mFromHeight = view.getHeight();
}

@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
    int newHeight;
    newHeight = (int) (mFromHeight * (1 - interpolatedTime));
    mView.getLayoutParams().height = newHeight;
    mView.setAlpha(1 - interpolatedTime);
    mView.requestLayout();
}

@Override
public void initialize(int width, int height, int parentWidth,
        int parentHeight) {
    super.initialize(width, height, parentWidth, parentHeight);
}

@Override
public boolean willChangeBounds() {
    return true;
}
}
Run Code Online (Sandbox Code Playgroud)

那就是我使用它的方式

View tv = ...
Animation a = new FadeUpAnimation(tv);
a.setInterpolator(new AccelerateInterpolator());
a.setDuration(300);
tv.setAnimation(a);
tv.startAnimation(a);
Run Code Online (Sandbox Code Playgroud)

您可以使用它来查看是否可以满足您的需求.