In onCreateView, the width and height of objects are not yet defined. They are identified at a later stage in the life cycle of an activity.
For this you need to use treeviewobserver.
Example with your rootview:
rootView.ViewTreeObserver.GlobalLayout += (object sender, EventArgs e) => { Console.WriteLine ("{0}x{1}", rootView.Width,rootView.Height); };
In this method, the width and height will be known.
In addition, you want to take a snapshot of your root view, the best way to do this is to use this method, this will automatically output the raster image of the view to the variable b.
rootView.DrawingCacheEnabled = true; Bitmap b = rootView.GetDrawingCache(true);
Hope this helps you!
Philippe creytens
source share