view.measure()抛出null异常

时间:2018-10-02 02:36:40

标签: xamarin xamarin.forms xamarin.android

在Xamarin中进行页面渲染时,调用OnLayout时遇到应用程序崩溃。 view.Measure(msw,msh)抛出空异常。

protected override void OnLayout(bool changed, int l, int t, int r, int b)
{
    base.OnLayout(changed, l, t, r, b);

    var msw = MeasureSpec.MakeMeasureSpec(r - l, MeasureSpecMode.Exactly);
    var msh = MeasureSpec.MakeMeasureSpec(b - t, MeasureSpecMode.Exactly);

    view.Measure(msw, msh);
    view.Layout(0, 0, r - l, b - t);
}

`

0 个答案:

没有答案