Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
BlackBerry HorizontalFieldManager校准_Blackberry - Fatal编程技术网

BlackBerry HorizontalFieldManager校准

BlackBerry HorizontalFieldManager校准,blackberry,Blackberry,在水平方向上,我想显示两个位图,在它们之间显示一个标签字段。 代码看起来很简单,但所有字段都添加在屏幕的左侧 HorizontalFieldManager hfm = new HorizontalFieldManager(); callbmp = new BitmapField(ei.getBitmap(),Field.FOCUSABLE |BitmapField.FIELD_LEFT); LabelField NAME = new LabelField("mylable", LabelFie

在水平方向上,我想显示两个位图,在它们之间显示一个标签字段。 代码看起来很简单,但所有字段都添加在屏幕的左侧

HorizontalFieldManager hfm = new HorizontalFieldManager();

callbmp = new BitmapField(ei.getBitmap(),Field.FOCUSABLE |BitmapField.FIELD_LEFT);
LabelField NAME = new LabelField("mylable", LabelField.FIELD_HCENTER);
mailbmp = new BitmapField(mail.getBitmap(),Field.FOCUSABLE|BitmapField.FIELD_RIGHT);
hfm.add(callbmp);
hfm.add(NAME);
hfm.add(mailbmp);
add(hfm);
按字段的添加顺序从左到右排列字段。忽略水平布局的样式位


如果您想要在水平线上左、右和居中,您需要一个自定义管理器。

这应该是您的要求:
 Manager customManager = new Manager(0)
 {
     protected void sublayout(int width, int height) {
         setPositionChild(
             getField(0), 
             0, 
             0);
         layoutChild(
             getField(0), 
             getField(0).getPreferredWidth(), 
             getField(0).getPreferredHeight());

         setPositionChild(
             getField(1), 
             Graphics.getScreenWidth()/2 - getField(1).getPreferredWidth()/2, 
             0);
         layoutChild(
             getField(1), 
             getField(1).getPreferredWidth(), 
             getField(1).getPreferredHeight());    

         setPositionChild(
             getField(2), 
             Graphics.getScreenWidth() - getField(2).getPreferredWidth(), 
             0);
         layoutChild(
             getField(2), 
             getField(2).getPreferredWidth(), 
             getField(2).getPreferredHeight());    

         setExtent(width, height);
     }      
 };

 customManager.add(new BitmapField(Bitmap.getBitmapResource("image1.png")));
 customManager.add(new LabelField("Hello Alignment"));
 customManager.add(new BitmapField(Bitmap.getBitmapResource("image2.png")));

只需减去您在水平字段管理器上添加的项目的宽度即可完成。默认情况下,
leftButton
或您在HFM上添加的第一个项目将添加到左侧。然后,您可以按以下方式添加标签(
userName
)和
right按钮:

LabelField userName = new LabelField("MaheshBabu");
HorizontalFieldManager horizontalBar = new HorizontalFieldManager(USE_ALL_WIDTH|Manager.NO_HORIZONTAL_SCROLL|Manager.NO_HORIZONTAL_SCROLLBAR);
horizontalBar.setBackground(BackgroundFactory.createSolidBackground(Color.BLACK));

rightButton.setMargin(0, 0, 0, Display.getWidth()-rightButton.getPreferredWidth()-leftButton.getPreferredWidth()-userName.getPreferredWidth());

horizontalBar.add(leftButton);
horizontalBar.add(userName);
horizontalBar.add(rightButton);

非常感谢。。你可以发布一些代码吗?我如何在定制管理器中安排左、右和中。这将是我在时间上的一项重大投资,只会伤害到你——你需要自己学习如何做到这一点。RIM在上一次的devcon上讨论了高级布局,其中包括一位这样做的经理,但我现在找不到。