To get the screen size from either iOS, Android, or Windows Phone you could use the following examples:
//ANDROID int intHeight = (int)Resources.DisplayMetrics.HeightPixels / Resources.DisplayMetrics.Density; int intWidth = (int)Resources.DisplayMetrics.WidthPixels / Resources.DisplayMetrics.Density; //IOS int intHeight = UIScreen.MainScreen.Bounds.Height; int intWidth = UIScreen.MainScreen.Bounds.Width; //WINPHONE int intHeight = Window.Current.Bounds.Height; int intWidth = Window.Current.Bounds.Width; |
To get screen size from any one of the platforms in a shared code base you could include conditional compile directives as follows:
int intHeight = 0; int intWidth = 0; #if __ANDROID__ intHeight = (int)Resources.DisplayMetrics.HeightPixels / Resources.DisplayMetrics.Density; intWidth = (int)Resources.DisplayMetrics.WidthPixels / Resources.DisplayMetrics.Density; #end if #if __IOS___ intHeight = UIScreen.MainScreen.Bounds.Height; intWidth = UIScreen.MainScreen.Bounds.Width; #endif #if WINDOWS_PHONE_APP intHeight = Window.Current.Bounds.Height; intWidth = Window.Current.Bounds.Width; #endif |