03-02-2011 03:36 PM
I have a screen form with two editFields and a button. What I want to do is to make them appears one under the other in the middle of the screen, like in this picture:
I tryed using 3 HorizontalFieldManager with
Manager.FIELD_VCENTER. inside a VerticalFieldManager created with Manager.USE_ALL_WIDTH style, but the fields appears on the top of the screen and they take all the width of the screen.
Solved! Go to Solution.
03-02-2011 04:05 PM
Since the main manager of your screen is VerticalFieldManager (you are using MainScreen, aren't you?), it will (understandably) ignore child fields' FIELD_VCENTER flags. It will, however, honor any horizontal alignment flags such as FIELD_HCENTER. However, FIELD_HCENTER does not play well with USE_ALL_WIDTH, so drop the latter. HorizontalFieldManager does honor its children's FIELD_VCENTER - you will have to use it to leverage this fact.
This might sound a little complicated at first, so I'll give you some more details:
1) Create your MainScreen with the explicit NO_VERTICAL_SCROLL style bit (important!)
2) Add a HorizontalFieldManager(USE_ALL_WIDTH | USE_ALL_HEIGHT) to the screen - let's call is bigHFM
3) Add a VerticalFieldManager(USE_ALL_WIDTH | FIELD_VCENTER) to bigHFM - let's call this new manager bigVFM
4) Create a HorizontalFieldManager(FIELD_HCENTER) - let's call it firstRow - and add it to bigVFM
5) Similarly, create a HorizontalFieldManager(FIELD_HCENTER) called secondRow and add it to bigVFM
6) Add LabelField("Label 1") and an edit field to firstRow
7) Add LabelField("Label 2") and another edit field to secondRow
8) Create a ButtonField("Button", FIELD_HCENTER) and add it to bigVFM
9) Run the application, look at the screen, tweak field margins if you feel like it and enjoy!
P.S.: albeit Field.setMargin is documented only in 6.0, it's been working like that since at least 4.2.0
03-02-2011 04:27 PM
Thanks for your answer, I made everything you told and now the fields are all vertically centered but labels don't appear and editFields takes all the width of the screen, how can I solve this?
03-02-2011 05:02 PM - last edited on 03-02-2011 05:26 PM by Taylarie
1) Are you adding labels before edit fields? It is important!
2) edit fields will indeed grab all width if left unchecked. I've already shown how to keep them contained in the following post - please take a look:
Post here is you still have problems.