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);
    }
  • 相关阅读:
    Vue 项目刷新当前页面
    Vue 使用 vue-echarts 图表插件
    Vue 路由跳转、传参、接参四种方式
    webpack 之 proxyTable 设置跨域
    二元函数的梯度下降法求解
    2020暑期华为勇敢星实习总结
    时间序列预测算法-ARIMA算法
    航天一院介绍
    腾讯数据分析笔试
    C# Fleck的WebSocket使用
  • 原文地址:https://www.cnblogs.com/xiaoa/p/8365531.html
Copyright © 2011-2022 走看看