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


    启动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);
    }
  • 相关阅读:
    网络需求分析课堂作业
    工程招标与投标课堂作业
    burpsuite Pro下载安装及破解 | JDK安装和配置
    渗透测试环境的搭建
    web应用基础架构
    为Linux环境安装图形化界面
    Linux基本操作
    markdown语法教程(更新中)
    VMware导入和删除虚拟机文件
    Java求幂集与List的浅拷贝深拷贝问题
  • 原文地址:https://www.cnblogs.com/xiaoa/p/8365531.html
Copyright © 2020-2023  润新知