我正在使用自定义动画来扩展和收缩我的视图,在 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;
}
}