2016-04-19 14 views
0

私は、Formsのアプリケーションと私はデバイスの向きと回転に私を助けることができるかどうかだけで私は仕事をしています。Xamarinフォームデバイスの向き

基本的には、私は3行の画像ボタンを持っています。私がしたいのは、デバイスが横向きに回転しているとき、すべてのボタンがすべて3つの縦の行ではなく1つの横の行に表示されることです。

これにはどのような方法が最適でしょうか? Androidで、別のxmlレイアウトファイルを作成して参照するだけで、XamarinフォームとXAMLと同様の方法がありますか?誰もがそれは素晴らしいだろう手助けができれば

<?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> 

は、私は私のMainPage.xamlを以下を提供します。

+0

ここで詳しく説明します。https://developer.xamarin.com/guides/xamarin-forms/user-interface/layouts/device-orientation/ –

答えて

1

フォームは(まだ)OnRotationイベントを持っていない - しかし、あなたは、必要に応じてあなたが水平から垂直にごStackLayoutの向きを変えることができるOnSizeAllocated

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

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

を使用して似たような達成することができます。

フォームのオリエンテーションについては、hereで詳しく説明しています。

関連する問題