2016-04-19 29 views
0

Ich arbeite an einer Forms App und ich frage mich nur, ob mir jemand mit Geräteausrichtung und -rotation helfen könnte.Xamarin Forms Geräteausrichtung

Grundsätzlich habe ich im Moment drei Reihen von Bildschaltflächen. Was ich tun möchte, ist, wenn das Gerät in Querformat gedreht wird, dann werden alle Knöpfe alle auf einer horizontalen Linie anstelle von 3 vertikalen Reihen angezeigt.

Was wäre der beste Ansatz dafür? Ich weiß in Android Sie nur eine andere XML-Layout-Datei erstellen und nur verweisen, gibt es eine ähnliche Möglichkeit, das in Xamarin Forms und XAML zu tun?

Ich werde mein MainPage.xaml unten liefern:

<?xml version="1.0" encoding="utf-8" ?> 
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"   x:Class="MyApp_Crossplatform.Views.MainPage" 
      Title="App" 
      BackgroundColor="White"> 
    <ContentPage.Content> 
    <StackLayout Padding="10" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" Orientation="Vertical"> 
     <!--Main container layout--> 
     <StackLayout VerticalOptions="Fill" HorizontalOptions="Center" Orientation="Vertical"> 
     <!--Layout for each menu component--> 
     <StackLayout VerticalOptions="StartAndExpand" HorizontalOptions="CenterAndExpand" Orientation="Horizontal"> 
      <Image 
      x:Name="btnSocial" 
      Source="imgsocial.png" 
      WidthRequest="100" 
      HeightRequest="100" 
      VerticalOptions="CenterAndExpand" 
      HorizontalOptions="CenterAndExpand"/> 
      <Image 
      x:Name="btnCareer" 
      Source="imgcareer.png" 
      WidthRequest="100" 
      HeightRequest="100" 
      VerticalOptions="CenterAndExpand" 
      HorizontalOptions="CenterAndExpand"/> 
     </StackLayout> 
     <StackLayout VerticalOptions="StartAndExpand" HorizontalOptions="CenterAndExpand" Orientation="Horizontal"> 
      <Image 
      x:Name="btnSchedule" 
      Source="imgschedule.png" 
      WidthRequest="100" 
      HeightRequest="100" 
      VerticalOptions="CenterAndExpand" 
      HorizontalOptions="CenterAndExpand"/> 
      <Image 
      x:Name="btnContact" 
      Source="contact.png" 
      WidthRequest="100" 
      HeightRequest="100" 
      VerticalOptions="CenterAndExpand" 
      HorizontalOptions="CenterAndExpand"/> 
     </StackLayout> 
     <StackLayout VerticalOptions="StartAndExpand" HorizontalOptions="CenterAndExpand" Orientation="Horizontal"> 
      <Image 
      x:Name="btnDetails" 
      Source="imgdetails.png" 
      WidthRequest="100" 
      HeightRequest="100" 
      VerticalOptions="CenterAndExpand" 
      HorizontalOptions="CenterAndExpand"/> 
     </StackLayout> 
     </StackLayout> 
    </StackLayout> 
    </ContentPage.Content> 
</ContentPage> 

Wenn jemand, dass wäre toll helfen kann.

+0

Dies wird hier ausführlich erklärt: https://developer.xamarin.com/guides/xamarin-forms/user-interface/layouts/device-orientation/ –

Antwort

1

Forms kein OnRotation Ereignis (noch) nicht - aber Sie etwas ähnliches unter Verwendung OnSizeAllocated

protected override void OnSizeAllocated(double width, double height) 
{ 
    base.OnSizeAllocated(width, height); //must be called 

    if (width > height) { 
     // landscape 
    } else { 
     // portrait 
    } 
} 

Sie könnten dann die Ausrichtung des StackLayout ändern von horizontal auf vertikal nach Bedarf erreichen können.

Orientierung in Forms wird genauer beschrieben here.