我正在尝试将动画应用于折叠LinearLayout。此动画取决于LinearLayout的MeasuredHeight属性,该属性的值大于0,但该值始终为0。
这是我正在使用的代码:
public void Collapse()
{
var v = FindViewById<LinearLayout>(Resource.Id.layoutBranding);
int initialHeight = v.MeasuredHeight; // always 0!!
var a = new MyAnimation(v, initialHeight);
a.Duration = (int)(initialHeight / v.Context.Resources.DisplayMetrics.Density);
v.StartAnimation(a);
}
其中MyAnimation定义为:
公共类MyAnimation:动画{私有只读View _view; 私有只读int _initalHeight;
public MyAnimation(View view, int initalHeight)
{
_view = view;
_initalHeight = initalHeight;
}
protected override void ApplyTransformation(float interpolatedTime, Transformation t)
{
if (interpolatedTime == 1)
{
_view.Visibility = ViewStates.Gone;
}
else
{
_view.LayoutParameters.Height = _initalHeight - (int) (_initalHeight*interpolatedTime);
_view.RequestLayout();
}
}
public override bool WillChangeBounds()
{
return true;
}
}
尝试这个:
v.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
int initialHeight = v.MeasuredHeight;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句