2016-12-22 2 views

ответ

4

Наиболее простой и точный способ получить по высоте устройства & ширину в PCL:

using Xamarin.Forms; 

namespace ABC 
{ 
    public class MyPage : ContentPage 
    { 
     private double _width; 
     private double _height; 

     public MyPage() 
     { 
      Content = new Label 
      { 
       WidthRequest = _width, 
       Text = "Welcome to Xamarin.Forms!" 
      }; 
     } 

     protected override void OnSizeAllocated(double width, double height) 
     { 
      base.OnSizeAllocated(width, height); 
      _width = width; 
      _height = height; 
     } 
    } 
} 
6

В этой демке App.ScreenWidth и App.ScreenHeight статические переменные, определенные в App классе и установленных в native проектов:

IOS приложение проекта:

App.ScreenWidth = UIScreen.MainScreen.Bounds.Width; 
App.ScreenHeight = UIScreen.MainScreen.Bounds.Height 

проект Android приложение:

App.ScreenWidth = (width - 0.5f)/density; 
App.ScreenHeight = (height - 0.5f)/density; 

Ссылка: https://github.com/xamarin/recipes/search?p=2&q=ScreenWidth&utf8=