Android Question AutoScale with programatically added views

Alwinl

Member
Licensed User
Longtime User
I kinda have a handle on layouts and scripting for different screen sizes but I was wondering how this would work with views that are added in code.
There is no real good reason I can think of not to use Layouts for everything, except for views like the Table as this is not one of the built-in Views.
Say I arrange a few views on a screen using a layout and leave a scroll area where I will put a table in, the table I create purely in code and add it to Scroll.Panel, will it also adhere to the Autoscale setting I have set in a designer script?
 

Alwinl

Member
Licensed User
Longtime User
Klaus - using the AutoScale module may work fine for scaling programmatically added views but then you loose the benefit preview and UI cloud etc.

What I was wondering is whether is it possible to add eg. a Table view using the layout designer or is the only option to use code?
 
Upvote 0

Alwinl

Member
Licensed User
Longtime User
Klaus - If I have some views added in the designer and scripted properly, and then add eg. a Table view in code, in what order should things happen with respect to:

.Loadlayout
ScaleAll(Activity, True)

Also, should I use ScaleAllDS or ScaleAll
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
If I have some views added in the designer and scripted properly...
it depends on what you mean with scripted properly.
You should not use AutoScale in the DesignerScripts.
In the Main module you should first load the layout(s) and then scale all views with ScaleAll:
.Loadlayout
ScaleAll(Activity, True)

The difference between ScaleAll and ScaleAllDS.
ScaleAllDS scales with the same equations like AutoScaleAll in the DesignerScripts.
ScaleAll scales with two scale factors one for each direction x and y.
You find a detailed explanation about the difference in chapter 8.10.3 AutoScale more advanced examples in the Beginner's Guide.

Best regards.
 
Upvote 0

Alwinl

Member
Licensed User
Longtime User
Thank you Klaus, your input (as well as the other guys on this forum) is just brilliant.

You say I shouldn't use AutoScale in the DS, should I still use the script for positioning views?
I'm thinking that after I LoadLayout, the views are not scaled (no AutoScale) but are positioned by the script, if I then call scale.ScaleAll surely this will mess with the postioning? By that I mean I would expect to need to do the order as follows:

.Loadlayout
ScaleAll
Reposition all views in code
 
Upvote 0

Alwinl

Member
Licensed User
Longtime User
I have revisited this again and another question has come up:

When scaling controls added in code, do I add them to the container first (with position/size is already set) and then call ScaleAll? eg.

pnlMain.AddView(txt1, 0, 0, 50dip, 20dip)
ScaleAll
'Surely at this point I would need to reposition again?
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
What exactly do you want to do ?
Is pnlMain already scaled or not ?
If pnlMain is scaled you should scale only txt1 with ScaleView(txt1) and reposition it afterwards if necessary.
Because if pnlMain is scaled and you call ScaleAll(pnlMain, True) pnlMain will be rescaled and be wrong !

Best regards.
 
Upvote 0
Top