Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Developer
borut123
Posts: 11
Registered: ‎11-22-2008
My Device: Not Specified

Layout manager, Field in the center of the screen

Hi

 

I want to position a single field  to the centre od the screen.

 

Which layout should I use to do that and how?

 

Currently I'm using FullScreen screen. But if it needs to be changed to MainScreen or anything else, I will change it.

 

thanks

Borut

 

Please use plain text.
Developer
Berrysoft
Posts: 143
Registered: ‎07-14-2008
My Device: Not Specified

Re: Layout manager, Field in the center of the screen

Your FullScreen has a single VerticalFieldManager delegate, which controls the layout and positioning of contained fields.

 

To precisely position a field within a manager, you'll have to create a custom field which contains x,y coordinates of where it is to be displayed relative to the containing manager, and then create a custom field manager which positions each field based on those coordinates.

 

Such a manger looks like this:

 

 

package net.berrysoft.dib.managers; import net.berrysoft.dib.interfaces.Placeable; import net.rim.device.api.ui.Field; import net.rim.device.api.ui.Manager; public class GameManager extends Manager { public GameManager() { super(Manager.NO_HORIZONTAL_SCROLL | Manager.NO_VERTICAL_SCROLL); } protected void sublayout(int width, int height) { Placeable field; // Loop through all the fields contained with the layout manager for(int i = 0; i < getFieldCount(); i++) { field = (Placeable)getField(i); // Get a field (the board) // Set the position of the field based on field's coordinates setPositionChild((Field) field, field.X(), field.Y()); layoutChild((Field) field, width, height); // Layout the field } setExtent(width, height); // Set the manager's dimensions } }

 

 Read about how to create a custom manager as well as the API docs to better understand this code.

 

Note that the above code assumes you have created an object with the public "getters"  X() and Y() which return the desired coordinates for the field to be displayed.

 

Patrick

 

 

Please use plain text.
New Developer
borut123
Posts: 11
Registered: ‎11-22-2008
My Device: Not Specified

Re: Layout manager, Field in the center of the screen

 

Thanks for the quick response.  I'll try it.

Please use plain text.