easier in designer or code?

markcrhome

Member
Licensed User
Longtime User
Is it possible to create a panel in the designer containing 3 labels and 2 imageviews, and then in the app startup, add this panel 7 times to a scroll view and still be able to respond to Click, and also to change label.text for each of them?

I do this programmatically, that is I create everything at runtime and not in the designer. This way I have been able to create an array of lables and imageviews, this gives me the ability to respond to events from them, and change individual elements.

The problem is that I do not understand how to resize the controls I have created at runtime for different devices. My target device was portrait mode 600 wide Galaxy Tab 7”, but since starting the boss now has a HTC Sensation, and the screen is different, so the hardcoded layout has to change.

It was my understanding that I could create a base panel in the designer, for each screen size I wished to support, and the device would choose the best fit. But How do I reference the labels on these panels? Would I have to create 7 base panels with all labels and images, and then do the exact same for each layout variant?

Also, I currently simply add a tag value to each view I add in a panel.
e.g. first panel added is element 0, thus the labels and images added have a tag of 0 applied.

This means I can easily reference views by the index, allowing me to change text etc and respond to clicks.

I can currently change it by lblName(2).Text = “NEW NAME HERE”
I can currently respond to a longlick by
B4X:
Sub lblName_LongClick
   
   Dim Send As View : Send=Sender
   lblName(Send.Tag).Text = lblName(Send.Tag).Text & " CLICKED! "

End Sub

So is this possible in the designer? Or do I stick with code and try understand how to resize controls on different screens?
 

derez

Expert
Licensed User
Longtime User
To my opinion you go in the right direction by using code - when you have such a large array of views, although you can define array vies in the designer as well - like textlabel(2).
To get over the size problem when doing it by code - use the %x and %y.
you can design one panel on the designer using a standard size (like 320x480 or 480x800), calculate the position and size in % of the activity width and height, and then delete the layout and use code.
Only if you need special size screens then you need to take additional measures, like checking the scale and multiplying by a special factor.
 
Last edited:
Upvote 0
Top