Strange behaviour setting btn_width designer vs. blocks

Hi!
Designing some buttons in a row and wanting them to use the full screen width I got some problems.
See aia and screenshot of AI_Companion.
My problem is that the value of the green btn.width attribute set in designer mode seems to be not effected by setting a new value to it with blocks.

With the btn.text attribute no problems.
Can anybody give some clarification?

Also I had some problems with the screensize attribute, which shows other figures than the specs of the device(s) In this link screen_size I read about CSS. So I may find out myself this problem. But if anybody can explain a bit, I would appreciate that very much!

strange_behaviour.aia (6.1 KB)

What are you expecting to see?

Thank you.
I expect that when I set the screen_width to a calculated value I will extract that value when I use "get btn_width" as a block.
And not the value I gave it in the designer mode.
As you see the read out value stays at 264 instead of the expected 240.

My advice is to not try to target a specific device based upon its given specifications.

Using the AI2 blocks of screen height and width (along with a clock timer - I see you didn't use one - to give the device time to catch up with itself), will be a more reliable method for sizing components on any given screen.

1 Like

The Designer is an approximation. If your app uses the Fixed Sizing setting you might get the response you expect, however using Responsive sizing works like this http://ai2.appinventor.mit.edu/reference/other/responsiveDesign.html . Contrary to what many App Inventor developers believe, setting to Responsive Sizing does not automatically set the app to make full use of the device screen. What you see is an approximation (actually a pretty good one) created to avoid having a set of images, buttons etc. for multiple screen sizes (as is required whilst using the professional Android Studio. Responsive sizing was intended as a simplification and compromise easily used by nascent developers. Make sure you read the section 3,

This tutorial might help you find a solution https://www.imagnity.com/tutorials/app-inventor/universal-screen-size-using-app-inventor/

How about this?

strange_behaviour_revised.aia (1.5 KB)

all done in designer

Thank you Tim and Steve,
My intention is to make btns and lbls of a size which is calculated from the device height and width to avoid distortion of the design.
I used the same method as discribed in the tutorial which Steve linked me to.
My problem is I can not "trust" the value of the green get btn.width:
When I calculate and set the first button, I cannot set the second button width to the "green attribute btn1_width"!
Instead I have to use a local variable which I used to set the width of btn1

So a work around is keeping a variable alive with the current chosen widths and heigths for later use in the initialization procedure. This work around is ok for my app, but I have to test it on other devices.

Sorry Tim,
Get stuck on server errors so I'm not able to see your aia now.

@TIMAI2, your revised version is excellent in its simpleness. I'll use this in future.

My problem has in this case nothing to do with buttons, but everything with assigning values. Specially values of properties of components.
My first lesson about strange behaviour with assigning was when I learned of linked-lists in AI2 from @ChrisWard, @ABG and @Juan_Antonio .
With lists, one should use "set list to copy-list" instead of "set list to get list". See other topic

Now I learn another lesson with an assignment out of a component property e.g. "green block Button1.Text".
But this time I think its a real bug.
When you change this revision2 to the case with changing the text property instead of the width, everything works as expected. To my idea there is something wrong with this width property.
See my revision 2 as you have time:


strange_behaviour_revised_2.aia (4.6 KB)

No, not a bug, just a timing issue. AI2 needs a little time to fetch the new value for Button1.Width. You can overcome this with a clock:

or just do something similar to your second method:

3 Likes

Thank you!!

Do I understand this well :: ?

  • with time interval you set the timer to 50 ms

  • with timer.enabled=true you start a kind of "wait" period

  • when timer is finished Clock1.Timer event is started

This may clarify some problems i got with loading big files.

Yes

Clock

Well chaps, this has to be one of the best Forum Topics - an excellent example and description by TimAI2 and Han_AppInv taking the time to fully understand the solution.

:muscle:

Thank you @TIMAI2 1000x
and thank you @ChrisWard

Han

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.