ListView的动画单项 [英] ListView animate single item

查看:137
本文介绍了ListView的动画单项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在它的项目一个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.

有一个应用程序,它做这个权利。这就是所谓的<一个href="https://play.google.com/store/apps/details?id=ch.teamtasks.tasks&feature=more_from_developer#?t=W251bGwsMSwxLDEwMiwiY2gudGVhbXRhc2tzLnRhc2tzIl0.">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.

这篇关于ListView的动画单项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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