首页 > 移动平台 > 详细

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

时间:2018-01-27 14:23:39      阅读:335      评论:0      收藏:0      [点我收藏+]

 

 

启动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时获取屏幕宽高

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!