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);
    }
  • 相关阅读:
    4种方法教你如何截取JS字符串最后一位
    12种JS常用获取时间的方式
    拖动的模态框
    计算鼠标在盒子内的坐标
    offset与style的区别
    offset系列属性
    Words
    #一些真相# 和自己握手言和,不要期盼另一片荒岛可以让你变成陆地
    Stack为什么翻译成栈?- 根据字形来辨别容易混淆的堆和栈
    [Hardware] 机械硬盘和固态硬盘功耗对比
  • 原文地址:https://www.cnblogs.com/xiaoa/p/8365531.html
Copyright © 2011-2022 走看看