Skip to content

Instantly share code, notes, and snippets.

@baileysh9
Created April 29, 2016 17:46
Show Gist options
  • Save baileysh9/b9a831a61576edf28e19b631b2c7b7b1 to your computer and use it in GitHub Desktop.
Save baileysh9/b9a831a61576edf28e19b631b2c7b7b1 to your computer and use it in GitHub Desktop.
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
global::Xamarin.Forms.Forms.Init (this, bundle);
var metrics = Resources.DisplayMetrics;
var widthInDp = ConvertPixelsToDp(metrics.WidthPixels);
var heightInDp = ConvertPixelsToDp(metrics.HeightPixels);
App.ScreenWidth = metrics.WidthPixels;
App.ScreenHeight = metrics.HeightPixels;
LoadApplication (new App ());
}
public int ConvertPixelsToDp(float pixelValue)
{
var dp = (int) ((pixelValue)/Resources.DisplayMetrics.Density);
return dp;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment