2016-10-24 3 views
2

画面のサイズ(およびデバイスのイディオム?)によって、マスターページの幅が異なります。電話では画面幅の約80%ですが、タブレットでは320  dpのような一定のサイズに見えます。Xamarin.FormsのMaster-Detail Pageのマスターページの幅はどのくらいですか?

誰でもこの値の一般的な公式を知っていますか? Widthプロパティがまだ設定されていないときに、構築時にいくつかの要素をレイアウトするために使用したいと思います。

編集: 私はhow to get the current screen sizeを知っています。しかし、Xamarin.Formのマスター詳細ページのマスターページの幅はどのように関係していますか?それは画面全体をカバーするのではなく、デバイスに応じて異なる割合を占めます。

答えて

0

デバイスの実際の画面幅、高さ、および倍率を要求できます。

https://github.com/mattregul/Xamarin_GetDeviceScreensizeから)

IOSのAppDelegate.cs

[Register("AppDelegate")] 
    public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate 
    { 
     public override bool FinishedLaunching(UIApplication app, NSDictionary options) 
     { 
      global::Xamarin.Forms.Forms.Init(); 

      // Store off the device sizes, so we can access them within Xamarin Forms 
      App.DisplayScreenWidth = (double)UIScreen.MainScreen.Bounds.Width; 
      App.DisplayScreenHeight = (double)UIScreen.MainScreen.Bounds.Height; 
      App.DisplayScaleFactor = (double)UIScreen.MainScreen.Scale; 

      LoadApplication(new App()); 

      return base.FinishedLaunching(app, options); 
     } 
    } 

アンドロイドMainActivity.cs

[Activity(Label = "Xamarin_GetDeviceScreensize.Droid", Icon = "@drawable/icon", Theme = "@style/MyTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)] 
    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity 
    { 
     protected override void OnCreate(Bundle bundle) 
     { 
      TabLayoutResource = Resource.Layout.Tabbar; 
      ToolbarResource = Resource.Layout.Toolbar; 

      base.OnCreate(bundle); 

      // Store off the device sizes, so we can access them within Xamarin Forms 
      App.DisplayScreenWidth = (double)Resources.DisplayMetrics.WidthPixels/(double)Resources.DisplayMetrics.Density; // Width = WidthPixels/Density 
      App.DisplayScreenHeight = (double)Resources.DisplayMetrics.HeightPixels/(double)Resources.DisplayMetrics.Density; // Height = HeightPixels/Density 
      App.DisplayScaleFactor = (double)Resources.DisplayMetrics.Density; 

      global::Xamarin.Forms.Forms.Init(this, bundle); 

      LoadApplication(new App()); 
     } 
    } 

XamarinはApp.cs

フォーム
public class App : Application 
    { 
     public static double DisplayScreenWidth; 
     public static double DisplayScreenHeight; 
     public static double DisplayScaleFactor; 

     public App() 
     { 

      string ScreenDetails = Device.OS.ToString() + " Device Screen Size:\n" + 
            $"Width: {DisplayScreenWidth}\n" + 
            $"Height: {DisplayScreenHeight}\n" + 
            $"Scale Factor: {DisplayScaleFactor}"; 

      // The root page of your application 
      var content = new ContentPage 
      { 
       Title = "Xamarin_GetDeviceScreensize", 
       Content = new StackLayout 
       { 
        VerticalOptions = LayoutOptions.Center, 
        Children = { 
         new Label { 
          HorizontalTextAlignment = TextAlignment.Center, 
          FontSize = Device.GetNamedSize (NamedSize.Large, typeof(Label)), 
          Text = ScreenDetails 
         } 
        } 
       } 
      }; 

      MainPage = new NavigationPage(content); 
     } 

    } 
+0

ありがとうございました!残念ながら、私は画面サイズ([私はそれを行う方法をよく知っています](http://xforms-kickstarter.com/#referring-to-the-screen-size))を要求していませんが、幅Xamarin.Formのマスタ詳細ページのマスターページのうち、画面全体をカバーしていないもの。私はより明示的にするために質問を編集します。 – Falko

関連する問題