使得RichTextField水平居中在黑莓 [英] Making the RichTextField Horizontally Centered in Blackberry

查看:271
本文介绍了使得RichTextField水平居中在黑莓的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前Mainscreen如下:

My current Mainscreen looks like :

目前的code显示的每一行是这样的:

The current code for each line of display is like:

    RichTextField WeFix1 = new RichTextField("• Computer & Laptop", RichTextField.TEXT_JUSTIFY_HCENTER);

    VFMTitle1 = new VerticalFieldManager(Field.USE_ALL_WIDTH| Field.NON_FOCUSABLE);

    HFMTitle1 = new HorizontalFieldManager(FIELD_HCENTER);

    HFMTitle1.add(WeFix1);

  VFMTitle1.add(HFMTitle1);
add(VFMTitle21);

但是需要将其放置在一条直线上:

But need to it be positioned in a straight line :

推荐答案

有很多可能性。可以调整持有的服务列表的容器的边缘。你也可以让你的自定义字段经理,等等。

There are many possibilities. You can adjust the margin of the container that holds list of services. Also you can make your custom field manager, and many more.

选项1:调整保证金

VerticalFieldManager vfmServices = new  VerticalFieldManager(VerticalFieldManager.USE_ALL_WIDTH);

vfmServices.add(new RichTextField("• Computer & Laptop"));
vfmServices.add(new RichTextField("• Modem / Router / Switches"));
vfmServices.add(new RichTextField("• Printer / Scanner"));
vfmServices.add(new RichTextField("• Tablet"));

final int horizontalMargin = 30;
vfmServices.setMargin(0, horizontalMargin, 0, horizontalMargin);

add(vfmServices);

选项2:使用自定义字段经理

Option 2: Using a custom field Manger

VerticalFieldManager vfmServiceLists = new VerticalFieldManager(VerticalFieldManager.USE_ALL_WIDTH);

vfmServiceLists.add(new RichTextField("• Computer & Laptop"));
vfmServiceLists.add(new RichTextField("• Modem / Router / Switches"));
vfmServiceLists.add(new RichTextField("• Printer / Scanner"));
vfmServiceLists.add(new RichTextField("• Tablet"));

Manager mListContainer = new Manager(Manager.USE_ALL_WIDTH) {

    final int horizontalMargin = 30;

    protected void sublayout(int width, int height) {
        // this manager designed to contain only one list container.
        if (getFieldCount() == 1) {
            Field child = getField(0);
            layoutChild(child, width - 2 * horizontalMargin, height);
            // adjust manager height.
            height = child.getHeight();
            setPositionChild(child, horizontalMargin, 0);
        }

        setExtent(width, height);       
    }           
};

mListContainer.add(vfmServiceLists);
add(mListContainer);

[后来添加]

[Added Later]

由于 alishaik786 在评论所说,如果你使用的的LabelField代替RichTextField,您可以检查以下code,不使用任何保证金:

As alishaik786 suggested in comment, if you use LabelField instead of RichTextField, you can check following code, which doesn't use any margin:

VerticalFieldManager vfmServiceLists = new VerticalFieldManager();

vfmServiceLists.add(new LabelField("• Computer & Laptop"));
vfmServiceLists.add(new LabelField("• Modem / Router / Switches"));
vfmServiceLists.add(new LabelField("• Printer / Scanner"));
vfmServiceLists.add(new LabelField("• Tablet"));

Manager mListContainer = new Manager(Manager.USE_ALL_WIDTH) {
    protected void sublayout(int width, int height) {
        // this manager designed to contain only one list container.
        if (getFieldCount() == 1) {
            Field child = getField(0);
            layoutChild(child, width, height);
            // adjust manager height.
            height = child.getHeight();
            setPositionChild(child, (width - child.getWidth()) / 2, 0);
        }

        setExtent(width, height);       
    }           
};

mListContainer.add(vfmServiceLists);
add(mListContainer);

这篇关于使得RichTextField水平居中在黑莓的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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