1

我正在使用自定义动画来扩展和收缩我的视图,在 SO 上的另一个答案中找到。我的问题是,ApplyTransformation 永远不会被调用,因此没有任何反应。

还有什么我应该做的吗?

private void BrandTextClicked (object sender, EventArgs e)
{
    Animation animation = null;
    if (expanded) {
        animation = new ExpandAnimation (listView, 0, height);
    } else {
        animation = new ExpandAnimation(listView, height, 0);
    }
    animation.Duration = 500;
    animation.Interpolator = new AccelerateInterpolator(1);
    listView.Animation = animation;
    animation.StartNow ();
    listView.Invalidate ();

    expanded = !expanded;
}

...

public class ExpandAnimation : Animation {
    private int mStartHeight;
    private int mDeltaHeight;
    private View mContent;

    public ExpandAnimation(View content, int startHeight, int endHeight) : base() {
        mContent = content;
        mStartHeight = startHeight;
        mDeltaHeight = endHeight - startHeight;
    }

    public override void Initialize (int width, int height, int parentWidth, int parentHeight)
    {
        base.Initialize (width, height, parentWidth, parentHeight);
    }

    protected override void ApplyTransformation(float interpolatedTime, Transformation t) {
        ViewGroup.LayoutParams lp = mContent.LayoutParameters;
        lp.Height = (int) (mStartHeight + mDeltaHeight *
                           interpolatedTime);
        mContent.LayoutParameters = lp;
        mContent.RequestLayout();
    }

    public override bool WillChangeBounds() {
        return true;
    }
}
4

1 回答 1

0

我最终使用了 Android.Animation 包/命名空间和 ValueAnimation,如下所示:

    ValueAnimator animator = null;
    if (expanded) {
        handle.SetImageResource(Android.Resource.Drawable.ArrowDownFloat);
        animator = ValueAnimator.OfObject (new HeightEvaluator (listView), height, 0);
    } else {
        handle.SetImageResource(Android.Resource.Drawable.ArrowUpFloat);
        animator = ValueAnimator.OfObject (new HeightEvaluator (listView), 0, height);
    }

    animator.SetDuration(500);
    animator.SetInterpolator(new AccelerateInterpolator (1));
    animator.Start ();

    expanded = !expanded;
于 2013-03-16T00:54:06.413 回答