Hi,
i have an expand animation in an ListView. The problem is, that the first time the list element gets clicked and the expand animation is created and executed it is not smooth on the screen. It looks like the animation is jumping right to the end of the animation. This looks like a lag in the UI Thread.
The funny thing is: If i click the item again it the animation is running backwards to hide the body of the list element again and the next time i click and expand the body again it will run completely smooth.
The code for my animation:
public class ExpandAnimation : Animation
{
private View mAnimatedView;
private ViewGroup.MarginLayoutParams mViewLayoutParams;
private int mMarginStart, mMarginEnd;
private bool mIsVisibleAfter = false;
private bool mWasEndedAlready = false;
public ExpandAnimation(View view, int duration)
{
Duration = duration;
mAnimatedView = view;
mViewLayoutParams = (ViewGroup.MarginLayoutParams)view.LayoutParameters;
// decide to show or hide the view
mIsVisibleAfter = (view.Visibility == ViewStates.Visible);
mMarginStart = mViewLayoutParams.BottomMargin;
mMarginEnd = (mMarginStart == 0 ? (0- view.Height) : 0);
view.Visibility = ViewStates.Visible;
}
protected override void ApplyTransformation (float interpolatedTime, Transformation t)
{
base.ApplyTransformation(interpolatedTime, t);
if (interpolatedTime < 1.0)
{
mViewLayoutParams.BottomMargin = mMarginStart +
(int)((mMarginEnd - mMarginStart) * interpolatedTime);
mAnimatedView.RequestLayout ();
}
else if (!mWasEndedAlready)
{
mViewLayoutParams.BottomMargin = mMarginEnd;
mAnimatedView.RequestLayout ();
if (mIsVisibleAfter)
{
mAnimatedView.Visibility = ViewStates.Gone;
}
mWasEndedAlready = true;
}
}
}
In the layout there is one LinearLayout which contains two other LinearLayouts. The Headline and the body which should be expanded.
Does someone know what the problem can be or how i can solve this?
Kind regards, Hannes