从 Android.Support.V4.Fragment 获取 imageView 的 Height/Width(始终 return 为零)

Get Height/Width of imageView from Android.Support.V4.Fragment(always return zero)

我正在使用 V4.Fragments。所以从 activity 我正在创建我的片段的新实例,然后我开始交易。
主要问题是我的 imageview 控件(在 axml 中)定义为 Layout_width="match_parent"weightSum=1(身高)。
出于某种原因,我需要知道 height/width我的 imageView。
我尝试了什么:
创建了 class 实现了 IOnGlobalLayoutListener

     class GlobalLayoutListener : Java.Lang.Object, ViewTreeObserver.IOnGlobalLayoutListener
        {
            System.Action _OnGlobalLayout;

            public GlobalLayoutListener (System.Action onGlobalLayout)
            {
                this._OnGlobalLayout = onGlobalLayout;
            }

            public void OnGlobalLayout ()
            {
                _OnGlobalLayout ();
            }
        }

之后,在我的 V4.Fragment class 中,我正在这样做:

           public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
                {
                    Arguments = new Bundle();
                    View _View = inflater.Inflate(Resource.Layout.MyFragmentLayout, container, false);
                    imgView = _View.FindViewById<ImageView>(Resource.Id.imgView);

                Action CallBack = () =>
                {
                    ImgHeight = imgView.Height;
                    ImgWidth = imgView.Width;
                };
           //new instance of class,that implements IOnGlobalLayoutListener
            GlobalLayoutListener Global = new GlobalLayoutListener(CallBack);
            imgView.ViewTreeObserver.AddOnGlobalLayoutListener(Global);  
retun _View;
}

技巧无效。始终 return (height/width).
第二种变体,我直接在 MyFragment

中实现了 IOnGlobalLayoutListener 的接口
 public class MyCustomFragment : Android.Support.V4.App.Fragment,View.IOnTouchListener,ViewTreeObserver.IOnGlobalLayoutListener 
    {
        int ImgHeight;
        int ImgWidth;
        ImageView imgView;
        Bundle Arguments;

  public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
            {
                Arguments = new Bundle();
                View _View = inflater.Inflate(Resource.Layout.MyFragmentLayout, container, false);
                imgView = _View.FindViewById<ImageView>(Resource.Id.imgView);

        ViewTreeObserver Vto = imgView.ViewTreeObserver; //also tried with _View.ViewTreeObserver; result same
        Vto.AddOnGlobalLayoutListener(this);

    retun _View;
}  

同样的问题,没有解决。
我的最后一个变体是:

        public class MyCustomFragment : Android.Support.V4.App.Fragment
            {
                int ImgHeight;
                int ImgWidth;
                ImageView imgView;
                Bundle Arguments;



  public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
            {
                Arguments = new Bundle();
                View _View = inflater.Inflate(Resource.Layout.MyFragmentLayout, container, false);
                imgView = _View.FindViewById<ImageView>(Resource.Id.imgView);

        imgView.ViewTreeObserver.GlobalLayout += (sender, e) =>  //also tried with _View
                {
                    ImgHeight = imgView.Height;
                    ImgWidth = imgView.Width;
                };

    retun _View;
}    

又一次不走运,我做错了什么?谢谢。

PS 对不起我的工程师。

一切正常,我做错了。
所以这段代码效果很好:

imgView.ViewTreeObserver.GlobalLayout += (sender, e) => 
                {
                     ImgHeight = imgView.Height;
                     ImgWidth = imgView.Width;
                };  

尽情享受吧!