码迷,mamicode.com
首页 > 移动开发 > 详细

Xamarin.Forms 启动App时获取屏幕宽高

时间:2018-01-27 15:29:42      阅读:325      评论:0      收藏:0      [点我收藏+]

标签:htm   constant   vbo   port   val   stack   print   padding   oncreate   

 

 

启动App时获取屏幕宽高

App.cs里面添加:
public static double ScreenWidth;
public static double ScreenHeight;
Android下 MainActivity.cs里面添加:
protected override void OnCreate(Bundle bundle)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
 
base.OnCreate(bundle);
 
global::Xamarin.Forms.Forms.Init(this, bundle);
 
 
var width = Resources.DisplayMetrics.WidthPixels;
var height = Resources.DisplayMetrics.HeightPixels;
var density = Resources.DisplayMetrics.Density; //
 
App.ScreenWidth = width / density; //
App.ScreenHeight = height / density; // 24 OnSizeAllocated
 
LoadApplication(new App());
}
IOS下 AppDelegate.cs里面添加:
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
global::Xamarin.Forms.Forms.Init();
 
App.ScreenWidth = UIScreen.MainScreen.Bounds.Width; //
App.ScreenHeight = UIScreen.MainScreen.Bounds.Height; //
 
LoadApplication(new App());
 
return base.FinishedLaunching(app, options);
}

Xamarin.Forms 启动App时获取屏幕宽高

标签:htm   constant   vbo   port   val   stack   print   padding   oncreate   

原文地址:https://www.cnblogs.com/xiaoa/p/8365531.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!