android - ListView 动画单项

标签 android listview animation

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

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

This little image should explain the problem

我目前的实现是这样的:

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

最佳答案

这是我创建的一个类(修改自 source I found here ),它可以为您提供所需的功能。

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

那我就是这样用的

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

您可以尝试一下,看看是否能满足您的需求。

关于android - ListView 动画单项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12009642/

相关文章:

android - 在 arrayAdapter ListView 中突出显示搜索到的文本

c# - ListView 项选择和异常处理

ios - 如何为约束更改设置动画?

jQuery ('html.body' ),动画不起作用

java - 获取 Mockito 错误 : "Wanted but not invoked... actually, there were zero interactions with this mock"

android - Robolectric 给出了一个异常(exception)

java - 警报对话框的处理结果如何? (安卓)

java - Ajax 不会在 wicket 中实现 ListView

javascript - 如何使视口(viewport)跟随此 javascript 代码中的矩形?

java - 我不明白监听器中 lambda 表达式的参数传递