4

I want to position my field at specified positions.

Maksym Gontar
  • 22,765
  • 10
  • 78
  • 114
Bohemian
  • 5,957
  • 11
  • 38
  • 47

1 Answers1

10

basically to set any field position amoung the manager, you shoud:

  1. override sublayout

removed dead ImageShack link

Code of extanded manager:

class CustomVerticalManager extends VerticalFieldManager {
 LabelField mText1 = new LabelField("top");
 LabelField mText2 = new LabelField("bottom");

 public CustomVerticalManager() {
  add(mText1);
  add(mText2);
 }

 public int getPreferredHeight() {
  return Display.getHeight();
 }

 public int getPreferredWidth() {
  return Display.getWidth();
 }

 protected void sublayout(int width, int height) {
  width = getPreferredWidth();
  height = getPreferredHeight();

  int fieldWidth = mText1.getPreferredWidth();
  int fieldHeight = mText1.getPreferredHeight();
  layoutChild(mText1, fieldWidth, fieldHeight);
  int xPos = (width - fieldWidth) >> 1;
  int yPos = 0;
  setPositionChild(mText1, xPos, yPos);

  fieldWidth = mText2.getPreferredWidth();
  fieldHeight = mText2.getPreferredHeight();
  layoutChild(mText2, fieldWidth, fieldHeight);
  xPos = (width - fieldWidth) >> 1;
  yPos = height - fieldHeight;
  setPositionChild(mText2, xPos, yPos);
  setExtent(width, height);
 }
}

Sample of use:

class Scr extends MainScreen {
 CustomVerticalManager mManager = new CustomVerticalManager();

 public Scr() {
  add(mManager);
 }
}

See also
Wireless - How to : Create a custom layout manager for a screen
Blackberry - fields layout animation

Community
  • 1
  • 1
Maksym Gontar
  • 22,765
  • 10
  • 78
  • 114
  • Good answer. RIM actually had a new class in the 5.0 API called AbsoluteFieldManager but for some reason removed it from the latest beta version. – Marc Novakowski Nov 19 '09 at 22:16