Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. //usage:
  2.  
  3. // ContactGrid is the x:Name of the Grid within the ScrollView
  4. protected override void OnAppearing()
  5. {
  6. base.OnAppearing();
  7. ContactGrid.LayoutStars(((float)App.INSTANCE.Resources["PageHeight"]));
  8. }
  9.  
  10. //In your MainActivity:
  11.  
  12.  
  13. private void InitAppResources()
  14. {
  15. App.INSTANCE.Resources["StatusBarHeight"] = GetStatusBarHeight() / Resources.DisplayMetrics.Density;
  16. App.INSTANCE.Resources["NavBarHeight"] = GetNavBarHeight() / Resources.DisplayMetrics.Density;
  17. App.INSTANCE.Resources["screenHeight"] = Resources.DisplayMetrics.HeightPixels / Resources.DisplayMetrics.Density;
  18. App.INSTANCE.Resources["screenWidth"] = Resources.DisplayMetrics.WidthPixels / Resources.DisplayMetrics.Density;
  19. App.INSTANCE.Resources["screenDensity"] = Resources.DisplayMetrics.Density;
  20. App.INSTANCE.Resources["PageHeight"] = (Resources.DisplayMetrics.HeightPixels - GetStatusBarHeight() - GetNavBarHeight()) / Resources.DisplayMetrics.Density;
  21. }
  22.  
  23. private int GetNavBarHeight()
  24. {
  25. int resourceId = Resources.GetIdentifier("navigation_bar_height", "dimen", "android");
  26. if (resourceId > 0)
  27. {
  28. return Resources.GetDimensionPixelSize(resourceId);
  29. }
  30. return 0;
  31. }
  32.  
  33. private int GetStatusBarHeight()
  34. {
  35. int resourceId = Resources.GetIdentifier("status_bar_height", "dimen", "android");
  36. if (resourceId > 0)
  37. {
  38. return Resources.GetDimensionPixelSize(resourceId);
  39. }
  40. return 0;
  41. }
  42.  
  43. //In your AppDelegate:
  44.  
  45.  
  46. private void InitAppResources()
  47. {
  48. App.INSTANCE.Resources["statusBarHeight"] = (float)(40 / UIScreen.MainScreen.NativeScale);
  49. App.INSTANCE.Resources["navBarHeight"] = (float)(88 / UIScreen.MainScreen.NativeScale);
  50. App.INSTANCE.Resources["screenHeight"] = (float)(UIScreen.MainScreen.NativeBounds.Height / UIScreen.MainScreen.NativeScale);
  51. App.INSTANCE.Resources["screenWidth"] = (float)(UIScreen.MainScreen.NativeBounds.Width / UIScreen.MainScreen.NativeScale);
  52. App.INSTANCE.Resources["screenDensity"] = (float)UIScreen.MainScreen.NativeScale;
  53. App.INSTANCE.Resources["pageHeight"] = (float)((UIScreen.MainScreen.NativeBounds.Height - 40 - 88) / UIScreen.MainScreen.NativeScale);
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement