java - VerticalFieldManager 不滚动

标签 java blackberry

我正在开发一个应用程序,其中我在 LableField 中设置了大量文本,并且希望它在模拟器 8900 中可滚动。因此,我采用了 VerticalFieldManager并将LableField放入其中。我使用 VERTICAL_SCROLL 使 VerticalFieldManager 可滚动,并尝试使用 Manager.VERTICAL_SCROLL。但仍然不起作用。

我的代码

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.FontFamily;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.component.BitmapField;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.ui.decor.BackgroundFactory;

public class AboutM1 extends MainScreen {

    public AboutM1() {

        ((VerticalFieldManager) getMainManager())
                .setBackground(BackgroundFactory
                        .createSolidBackground(0xEDEDED));

        VerticalFieldManager TOPVFM = new VerticalFieldManager(USE_ALL_WIDTH);
        HorizontalFieldManager TOPHFM = new HorizontalFieldManager(
                FIELD_HCENTER | FIELD_VCENTER);
        // LabelField toplable = new LabelField("Welcome to");

        LabelField toplable = new LabelField("\n Welcome to", FIELD_BOTTOM) {
            public void paint(Graphics g) {
                g.setBackgroundColor(0xECECEC);
                g.fillRect(0, 0, getWidth(), getHeight());
                g.setColor(Color.RED);

                g.clear();
                super.paint(g);
            }
        };

        FontFamily fontFamily[] = FontFamily.getFontFamilies();
        Font font = fontFamily[1].getFont(FontFamily.CBTF_FONT, 20);
        font = fontFamily[1].getFont(Font.BOLD, 25);
        toplable.setFont(font);

        Bitmap bmp = Bitmap.getBitmapResource("logo36X36.png");
        BitmapField imgField = new BitmapField(bmp, FIELD_BOTTOM);

        TOPHFM.add(toplable);
        TOPHFM.add(imgField);

        TOPVFM.add(TOPHFM);

        int width = Display.getWidth();

        add(TOPVFM);
        LabelField Greenline = new LabelField(
                "_______________________________________") {
            protected void paint(Graphics g) {
                int oldColor = g.getColor();
                g.setColor(Color.GREEN);
                // g.fillRoundRect(0, 0, 50, 5, 7, 7);
                g.setColor(oldColor);
                super.paint(g);
            }

        };

        add(Greenline);

        VerticalFieldManager DescriptionVFM = new VerticalFieldManager(
                VERTICAL_SCROLL);
        LabelField Description = new LabelField(
                "\n asdasdawqwere we r we r we rw er w er wer, groceries, sadfertewrt er te rt ert er t er t er t er t . asdasdasdasdas asd asd werwerewrt er t erter t ert.",
                FIELD_HCENTER);
        LabelField Description2 = new LabelField(
                "\n\n\n About Us \n For customer care \n\n");
        /*
         * add(Description); add(Description2);
         */

        DescriptionVFM.add(Description);
        DescriptionVFM.add(Description2);

        VerticalFieldManager BottomVFM = new VerticalFieldManager(USE_ALL_WIDTH);
        HorizontalFieldManager BottomHFM = new HorizontalFieldManager(
                FIELD_VCENTER);
        LabelField callus = new LabelField("Call: ", FIELD_VCENTER);
        LabelField Number = new LabelField("+91-79-30487400", FIELD_VCENTER) {
            protected void paint(Graphics g) {
                g.setColor(0x324F85);

                // g.fillRoundRect(0, 0, 50, 5, 7, 7);
                super.paint(g);
            }

        };
        font = fontFamily[1].getFont(Font.BOLD, 18);
        Number.setFont(font);

        BottomHFM.add(callus);
        BottomHFM.add(Number);
        BottomVFM.add(BottomHFM);
        // add(BottomVFM);
        DescriptionVFM.add(BottomVFM);
        add(DescriptionVFM);

    }
}

最佳答案

当您将 LabelField 实例添加到任何 FieldManager 时,您需要在其后添加另一个虚拟可聚焦字段。

您可以使用NullField在这种情况下。尝试如下所示:

// fieldManger can be a VerticalFieldManger, HorizontalFieldManger, Manager, etc.
fieldManager.add(new LabelField("An instance of LabelField"));
fieldManager.add(new NullField(NullField.FOCUSABLE);

关于java - VerticalFieldManager 不滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11753575/

相关文章:

Java 的 Bigdecimal.divide 和 rounding

android - 在 Android 和黑莓项目之间共享 Java 逻辑?

blackberry - 当 PC 位于代理服务器后面时,如何在黑莓模拟器上制作应用程序以连接互联网

security - 在 Blackberry 应用程序中存储加密 key

blackberry - 在 black berry 中创建项目时 xml 文件出错

java - 我如何在 Blackberry 中执行 http get 请求

java - Fragment Android 背后的暗淡和模糊背景

java - 做了一个简单的数组,似乎有一个编译错误

java - SchedulerFactory 的单个实例可以有多少个触发器?

java - SortedMap 中的映射值