I can see the interest in using the Static modules for computing routines, but they seem to be overwelming limited...
I am trying to use a Static Code Module to set my Layouts dinamically, acording o physical specs of the running device, such as Height, With and Scale factors, and using one sub for each "activity" screen (notice the quotes, not as activity per say)... DIMming the views and setting the layoutvalues acording to the factors...
BUT, in orde to, in the corresponding Activity (un-quoted), add the created views, I HAVE to reset the layout, wich void the Code Module purpose...
Is there something I am missing?
Can I add a view to the activity without resetting its layout?
Sub First(Height As Int, Width As Int, Scale As Float)
ToastMessageShow(Height & "," & Width & "," & Scale, True)
Dim Label1 As Label
Label1.Initialize("")
Label1.Color = Colors.DarkGray
Select Scale
Case 1,0
Label1.SetLayout(9,131,299,30)
Case 1,5
Label1.SetLayout(14,219,45,448)
End Select
End Sub
Now how can I add to the main activity the views ( i was hopping to create them in the Static code Module and set their layout there also) without re-defining the layout?
The purpose of the First Sub is to create and set the views ( in this one its abou 5 or 6 of them) for the Main Activity Layout...
There will be other subs to set other activities layouts...with up to 30 views
BTW, why not use dip units instead? Why change the dimension manually?
I will be using dip values ( I hope ), but since there are so many screen sizes out there, I was thinking that, in oreder to suite the most common devices, I could target each screen individually, wich is less pronne to error than using the designer Layout set...
And of course, just for the eck of it...a learning experience...
You can pass the activity (or a panel) as the first parameter and then add the views to the activity (or panel).
I will be using dip values ( I hope ), but since there are so many screen sizes out there, I was thinking that, in oreder to suite the most common devices, I could target each screen individually, wich is less pronne to error than using the designer Layout set...
I recommend you to use layout variants with the designer to target multiple screens. The abstract designer makes it simple to test (and adjust) the layout for different types of devices.
dip unit is not related to the designer. Instead of specifying that the label's width is 100 pixels you should set it to be 100dip. This way it will scale automatically based on the device scale.
I must then Dim the passed string as Activity or Panel in the Static Code Module, correct?
I recommend you to use layout variants with the designer to target multiple screens. The abstract designer makes it simple to test (and adjust) the layout for different types of devices.
I know this, but for me it gets a bit tricky, as I tend to make changes in the designer without checking in wich variant I am working on....
dip unit is not related to the designer. Instead of specifying that the label's width is 100 pixels you should set it to be 100dip. This way it will scale automatically based on the device scale.
While in the Width values this is TRUE, With my SGS (480x800) I found that simple dip scaling is not enough, and I am usually left with unsused space at the bottom...
Since there are so many screen sizes and resolutions, and some of them seems to escape the "standarts", I prepefer to take this in my own hands...
I think I have found a HUGE limitation on Static Code modules...
While variables declared in a static module can be used and accessed all across the project, a View created within a Static Code Module Sub can only be accessed inside that Sub!!!
Also, even though, at runtime the view is created and added to the activity, in codding time I find NO means of accessing a view ( created in a Static Code Module) in an activity module...
Am I correct in theses findingd??? (In B4Ppc we add not these limitaions...)
The problem is, that it doesn't even alow us to refer to a view outside the sub were it was declares/created in, throwing a "use of undeclared variable" error warning!!!! (So I cannot even compile it!)
I am trying to use a Static Code Module to set my Layouts dinamically, acording o physical specs of the running device, such as Height, With and Scale factors, and using one sub for each "activity"
I am also trying to use Code modules create the layout and handle the events for the created panel. This so I can have more control on the layout and make the code more readeble for me as I try to have everything for that panel in one module. Its a bit more work but with using precentages and dips I have the same layout on my mobile devices.
While variables declared in a static module can be used and accessed all across the project, a View created within a Static Code Module Sub can only be accessed inside that Sub!!!
Also, even though, at runtime the view is created and added to the activity, in codding time I find NO means of accessing a view ( created in a Static Code Module) in an activity module...
This is normal as it is a local variable for that sub. What I do is give the view properties in the tag with a panel Id and a unique View Id. This way you can always find the view when you need it later.
Would be nice if we had Defines.
HTH