水平定心字段在垂直场管理 [英] Horizontally centering fields in a vertical field manager

查看:159
本文介绍了水平定心字段在垂直场管理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

vfm = new VerticalFieldManager(Manager.VERTICAL_SCROLL);
    vfm.add(new LabelField("horizontally centered...",Field.FIELD_HCENTER | LabelField.FOCUSABLE));
    vfm.add(new LabelField("horizontally centered...",Field.FIELD_HCENTER | LabelField.USE_ALL_WIDTH | LabelField.FOCUSABLE));

    add(vfm);

为什么我不能让我的领域进行水平对齐。我曾尝试不同的组合,但不能得到一个单一的labelField为中心。如果我下面添加第二个字段USE_ALL_WIDTH然后在前场被居中。

Why can't I get my fields to be horizontally aligned. I have tried different combinations but can't get a single labelfield to be centered. If I add a second field below with USE_ALL_WIDTH then the first field gets centered.

我不知道这样做的正确方法!

I don't know what the proper way of doing it!

编辑:

随着下面的链接提供的,我试图做:

Following the link provided below, I tried doing:

vfm = new VerticalFieldManager(Field.USE_ALL_WIDTH | Field.USE_ALL_HEIGHT){


        protected void sublayout( int width, int height ) {

            super.sublayout( width, height );

            width = getWidth();
            height = getHeight();

            for (int i = 0;i < this.getFieldCount() - 1; i++)
            {
                System.out.println("field:" + i);
                Field field = this.getField(i);
                //this positions the item in the middle of the manager
                int x = (int)((width - field.getWidth()) * 0.50);
                setPositionChild(field, x, field.getTop());
            }
        }


    };


    vfm.add(new LabelField("Facebook"));


    add(vfm);

问题是,我没有得到任何字段。我怎么来实现它?

The problem is that I'm not getting any fields. How am I supposed to implement it?

推荐答案

下面是规则为在BlackBerry对齐方式:

Here are the rules for alignment on BlackBerry:


  • A Horizo​​ntalFieldManager 只能对准其中的字段的纵向即可。因此,只有建立这些领域的下列样式(也称为同步比特)的时候有任何作用:FIELD_TOP,FIELD_VCENTER,FIELD_BOTTOM。例如新的LabelField(我的场,Field.Field_VCENTER)

  • A HorizontalFieldManager can only align the fields within it vertically. So when creating those fields only the following styles (also known as alignment bits) have any effect: FIELD_TOP, FIELD_VCENTER, FIELD_BOTTOM. e.g. new LabelField("My field", Field.Field_VCENTER)

Horizo​​ntalFieldManager例如


  • A VerticalFieldManager 只能对准其中的字段的横向即可。只有下列方式产生任何影响。FIELD_LEFT,FIELD_HCENTER,FIELD_RIGHT

  • A VerticalFieldManager can only align the fields within it horizontally. Only the following styles have any effect: FIELD_LEFT, FIELD_HCENTER, FIELD_RIGHT.

VerticalFieldManager例如

对齐水平和垂直方向的例子

下面是其中垂直和水平对齐屏幕中央的按钮的例子:

Here's an example which aligns a button in the center of the screen both vertically and horizontally:

public class AlignmentScreen extends MainScreen{

        public AlignmentScreen(){

            //A MainScreen has a VerticalFieldManager to lay out its 
            //fields from top to bottom, the style bits here tell it
            //to span the whole width of the screen and not to scroll
            super(Manager.USE_ALL_WIDTH | Manager.NO_VERTICAL_SCROLL);

            //Set the VerticalFieldManager to have a GREEN background
            getMainManager().setBackground(BackgroundFactory.createSolidBackground(0xFF00FF00));

            //Create a new HorizontalFieldManager which is centered horizontally
            //and spans the whole height of the containing VerticalFieldManager
            HorizontalFieldManager hfm = new HorizontalFieldManager(Field.FIELD_HCENTER | Manager.USE_ALL_HEIGHT);

            //Set the HorizontalFieldManager's background to RED
            hfm.setBackground(BackgroundFactory.createSolidBackground(0xFFFF0000));

            //Create a button and center align it vertically
            ButtonField button = new ButtonField("Test", Field.FIELD_VCENTER);

            //Add the button to the HoriztonalFieldManager
            hfm.add(button);

            //Add the HorizontalFieldManager to the VerticalFieldManager
            add(hfm);
        }
    }

屏幕应该是这样的:

The screen should look like this:

您应该能修改上面让你的领域对准您想要的方式。

You should be able to modify the above to get your fields to align the way you want.

这篇关于水平定心字段在垂直场管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆