zoukankan      html  css  js  c++  java
  • 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);
    }
  • 相关阅读:
    首次搭建微信小程序记录各种细节
    vue3.x 首次搭建
    通过nodejs 下载阿里云省、市、区的json文件,使用在echart上
    vscode
    使用 ts + and design + react-redux + react-router-dom + ahook 开发 管理后台
    Python 字典(dict) 操作基础
    高斯混合模型视频背景建模的EM算法与Matlab 实现
    Tensorflow 10分钟快速上手
    Ubuntu16.04LTS 搜狗输入法无法输入中文
    Machine Learning Class 1:Introduction,supervised & unsupervised learning
  • 原文地址:https://www.cnblogs.com/xiaoa/p/8365531.html
Copyright © 2011-2022 走看看