c# - Xamarin Forms device orientation -


im working on forms app , im wondering if me device orientation , rotation.

basically @ moment have 3 rows of image buttons. want when device rotated landscape, of buttons displayed on 1 horizontal line instead of 3 vertical rows.

what best approach this? know in android create xml layout file , reference that, there similar way in xamarin forms , xaml?

i provide mainpage.xaml below:

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

if can great.

forms doesn't have onrotation event (yet) - can achieve similar using onsizeallocated

protected override void onsizeallocated(double width, double height) {     base.onsizeallocated(width, height); //must called      if (width > height) {       // landscape     } else {       // portrait     } }  

you change orientation of stacklayout horizontal vertical needed.

orientation in forms discussed in more detail here.


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -