Change table arrangement (cols x rows) in response to device orientation change

218 views
Skip to first unread message

frds...@gmail.com

unread,
May 26, 2014, 9:29:37 AM5/26/14
to mitappinv...@googlegroups.com, Fernando Silveira

Hi, 

My app has a grid of images defined in a Table Arrangement 3 cols x 5 rows as presented in #1 in the attached image (Attention: Images are hardcoded on each cell!!!)

I want to have the grid presented as #2 (5 cols x 3 rows) when the device is in LANDSCAPE orientation.

  1. Can I change the cols/rows properties from 3x5 to 5x3 in response to the orientation change?
  2. If I do so, do I have to reload the images so they appear in the sequence presented in #2 image?


Regards,
Fernando

MIT App Inventor 2
Built: May 25 2014 Version: nb133a
Use Companion: 2.18ai2zx1
Windows 7 - 64 bits 
Help - screen rotation vs table arrangement.jpg

Taifun

unread,
May 26, 2014, 9:42:29 AM5/26/14
to mitappinv...@googlegroups.com
Can I change the cols/rows properties from 3x5 to 5x3 in response to the orientation change?
unfortunately not
you have to define additionally a hidden table arrangements 5x3 with new image components inside, then after turning the device into landscape mode, set the first table arrangement to visible = false and the second table arrangement to visible = true
Taifun

Trying to push the limits of App Inventor! Snippets and Tutorials from Pura Vida Apps by Taifun.         

frds...@gmail.com

unread,
May 26, 2014, 9:48:09 AM5/26/14
to mitappinv...@googlegroups.com, Fernando Silveira
Uhmmm... I'm affraid I won't be able to change Table Arrangement cols x rows in runtime... :-(

Instead, I thought I could use two predefined Table Arrangements one for PORTRAIT and other for LANDSCAPE and turn each one visible/invisible when device rotates. BUT I don't one to duplicate the buttons and the existing logic. 

Any ideas to address this without much code change/duplication?

Regards,
Fernando

frds...@gmail.com

unread,
May 26, 2014, 9:49:37 AM5/26/14
to mitappinv...@googlegroups.com
That's exactly what I just found. Thanx

But doing so I have to also duplicate buttons and the logic, right?

Regards
Fernando

Taifun

unread,
May 26, 2014, 10:08:39 AM5/26/14
to mitappinv...@googlegroups.com
you will have duplicate buttons, but instead of duplicating the logic, you can define procedures and call these after each button click
Taifun

frds...@gmail.com

unread,
May 26, 2014, 3:59:48 PM5/26/14
to mitappinv...@googlegroups.com
I got you. Thanx again.

One last question. I set the screen orientation to "sensor" at design.
But there is no way to make it change when the device is swaped to any portrait or landscape. In run time the property screen rotation is always "sensor", I know because I'm seting a label with screen1.screenorientation value for debugging purposes and it shows "sensor" whenever I move the device.

Please, have a look to the image attached and see what I am doing wrong.

Regards,

Help - screen rotation code.jpg

Taifun

unread,
May 26, 2014, 4:07:31 PM5/26/14
to mitappinv...@googlegroups.com
just use 
if screen1.width > screen.height 
then landscape
else portrait
Taifun

Taifun

unread,
May 26, 2014, 4:09:34 PM5/26/14
to mitappinv...@googlegroups.com
btw. there is some redundancy in your blocks...
this is a great opportunity to create a procedure and call it both events ...

also probably it helps to read chapter 19 - 21 in Dave's book http://www.appinventor.org/projects to get an idea how to do DRY programming with App Inventor https://en.wikipedia.org/wiki/Don%27t_repeat_yourself

frds...@gmail.com

unread,
May 26, 2014, 4:27:45 PM5/26/14
to mitappinv...@googlegroups.com
Taifun, with your IF construction suggestion the application worked just as I wanted in terms of screen rotation. Thank you!

Regarding redundancy, I appreciate your comment but since there is only two instructions executed on each button click, I decided to keep then duplicated and save the "procedure effort" for when the code gets more complex.

Cheers!
Fernando

frds...@gmail.com

unread,
May 26, 2014, 4:37:42 PM5/26/14
to mitappinv...@googlegroups.com
Fixed the redundancy problem with a procedure to prepare_screen.

Thanx! :-D



Reply all
Reply to author
Forward
0 new messages