ListView的动画单项单项、动画、ListView

2023-09-04 11:18:39 作者:结局早已写好

我在它的项目一个ListView。 当用户点击一个项目它的高度应该扩展到零及以下的所有项目必须向上滚动。 我的code以下不工作。 用我的$ C C这被点击尺度权的项目$,但下列项目不滚动,他们留在同一位置。 我也试图与一个LinearLayout中,但有同样的问题。

I got a ListView with items in it. When the user clicks an item it's height should scale to zero and all items below should scroll up. My code below doesnt work. With my code the item which was clicked scales right, but the items below dont scroll up, they stay at the same position. I've also tried it with an LinearLayout but there is the same problem.

有一个应用程序,它做这个权利。这就是所谓的Tasks.

There is an app which does this right. It's called Tasks.

我目前的执行情况是这样的:

My current implementation looks like this:

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

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

推荐答案

下面是一个类我做了(从的源代码,我发现这里),可能给你你想要的功能。

Here's a class I made (modified from source I found here) that may give you the functionality you want.

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

然后,这是我如何使用它

Then this is how I'm using it

View tv = ...
Animation a = new FadeUpAnimation(tv);
a.setInterpolator(new AccelerateInterpolator());
a.setDuration(300);
tv.setAnimation(a);
tv.startAnimation(a);

您可以用它玩,看看你能得到它,以满足您的需求。

You can play with it to see if you can get it to fit your needs.