Screen rotation

How can I use the screen rotation feature to customize the width and height of items in landscape mode?

When Screen1.OrientationChanged
   if (Screen1.ScreenOrientation = Landscape ) then  
       set MyItem.Width to 80% of screen width
       set MyItem.Height to 60 pixels
   else // Portrait
       set MyItem.Width to 100% of screen width
       set MyItem.Height to 50 pixels

make it as procedure for every components or try anyother convenient logic which suits you most

wow Quick response thanks I will try it

if this does not work try Screen1.Height < Screen1.Width
Taifun

Friend, I am trying to change the size of the elements to a specific size when the screen is rotated Landscape, and the elements return to their normal size when the screen returns to Portrait.:slightly_smiling_face:

Yes of couse
Adjust the suggestion to your needs
What have you tried?

Taifun

When Screen1.OrientationChanged
if (Screen1.ScreenOrientation = Landscape ) then
set MyItem.Width to 80% of screen width
set MyItem.Height to 60 pixels
else // Portrait
set MyItem.Width to 100% of screen width
set MyItem.Height to 50 pixels

but not working

show us your blocks pls

It looks like you have overseen my first answer

Taifun

I know it’s simple but I can’t understand the problem

i hope this screen orientation does not trigger properly. Whnever yout ry first try to debug,


this works only with user adds orientation as landscape or portrait. it takes user chocie only. So better try with Taifun suggestion and try. let me think further about this

From the documentation User Interface

ScreenOrientation
Declares the requested screen orientation, specified as a text value. Commonly used values are landscape, portrait, sensor, user and unspecified.

So ScreenOrientation returns landscape, portrait, sensor, user orunspecified, it does not return the current screen rotation landscape or portrait

Therefore to detect if the screen is in landscape or portrait, use these blocks

if Screen1.Height < Screen1.Width
Then screen is in landscape
Else screen us in portrait

Taifun

can you send pic please I can’t understand it like that.

A very good way to learn App Inventor or Kodular is to read the free Inventor’s Manual here in the AI2 free online eBook App Inventor 2 Book: Create Your Own Android Apps … the links are at the bottom of the Web page. The book ‘teaches’ users how to program with AI2 blocks.

There is a free programming course here Course In A Box and the aia files for the projects in the book are here: App Inventor 2 Book: Create Your Own Android Apps

How to do a lot of basic things with App Inventor are described here: How do you...? .

Also do the tutorials Our Tutorials! to learn the basics of App Inventor, then try something and follow the Top 5 Tips: How to learn App Inventor

Taifun

See also

Taifun

You make the block and send it a picture so I can understand what these codes mean.

Now it changes the elements when the screen is in landscape mode but does not return them to normal when returning to portrait mode.

It would really help if you provided a screenshot your relevant blocks, so we can see what you are trying to do, and where the problem may be.

To get an image of your blocks, right click in the Blocks Editor and select “Download Blocks as Image”. You might want to use an image editor to crop etc. if required. Then post it here in the community.

Taifun

1 Like