垂直scrollview在Blackberry中不起作用

时间:2013-10-23 10:54:40

标签: blackberry scroll

在下面的代码scrollview不工作所有是这种形式的labelfields每当我在上面的代码中添加一个按钮字段滚动但当我删除它不工作所以我的问题是如何只有标签时滚动屏幕表格中的字段?

final VerticalFieldManager mainreportfractionsodiumvfm = new VerticalFieldManager(
            Manager.USE_ALL_HEIGHT | Manager.VERTICAL_SCROLL);

    // For action bar
    final HorizontalFieldManager vfm_r = new HorizontalFieldManager(
            Field.USE_ALL_WIDTH) {
        // Applying background color for that Manager
        public void paint(Graphics graphics) {
            graphics.setColor(Color.WHITE);
            graphics.setBackgroundColor(0Xde3f39);
            graphics.clear();
            super.paint(graphics);
        }

        // Placing the Fields

        protected void sublayout(int width, int height) {

            setPositionChild(getField(0), 0, 0);
            layoutChild(getField(0), getField(0).getPreferredWidth(),
                    getField(0).getPreferredHeight());

            setPositionChild(getField(1), Display.getWidth() / 2
                    - getField(1).getPreferredWidth() / 2, 0);
            layoutChild(getField(1), getField(1).getPreferredWidth(),
                    getField(1).getPreferredHeight());

            setPositionChild(getField(2), Display.getWidth()
                    - getField(2).getPreferredWidth(), 0);
            layoutChild(getField(2), getField(2).getPreferredWidth(),
                    getField(2).getPreferredHeight());

            setExtent(width, 35);
        }

    };

    final ButtonField bmpfield1 = new ButtonField("menu");
    // To display Home icon

    final Bitmap bmp2 = Bitmap.getBitmapResource("home.png");
    BitmapField bmpfield2 = new BitmapField(bmp2, Field.FOCUSABLE
            | Field.FIELD_RIGHT);

    // To display Title

    final VerticalFieldManager hfm_mainlbltext = new VerticalFieldManager(
            FIELD_HCENTER);
    LabelField lbl = new LabelField("Body Surface Area",
            Field.FIELD_VCENTER);
    LabelField lbl1 = new LabelField("Report", Field.FIELD_VCENTER);

    lbl.setFont(lbl.getFont().derive(Font.BOLD));
    lbl1.setFont(lbl1.getFont().derive(Font.BOLD));
    // setMargin(int top, int right, int bottom, int left)
    lbl1.setMargin(0, 0, 0, 50);
    hfm_mainlbltext.add(lbl);
    hfm_mainlbltext.add(lbl1);

    // //////////////////////////////////////////////////////////////////////////////
    // fields
    // ///////////////////////////////////////////////////////////////////////////////

    LabelField lbltxt1 = new LabelField(
            "A Fractional Excretion of Sodium (FENa)", FIELD_HCENTER) {
        protected void paint(Graphics g) {
            g.setColor(0xde3f39);
            super.paint(g);
        }
    };

    lbltxt1.setPadding(0, 5, 5, 5);
    lbltxt1.setFont(lbl.getFont().derive(Font.BOLD, 15));

    LabelField lbltxt2 = new LabelField(
            "1% suggests pre-renal disease, while > 1% is suggestive of acute tubular necrosis (ATN).",
            FIELD_HCENTER) {
        protected void paint(Graphics g) {
            g.setColor(0x6d6e76);
            super.paint(g);
        }
    };

    lbltxt2.setPadding(0, 5, 5, 5);
    lbltxt2.setFont(lbl.getFont().derive(Font.BOLD, 15));

    VerticalFieldManager hfm8 = new VerticalFieldManager();
    HorizontalFieldManager hfmresult = new HorizontalFieldManager();

    hfm8.setPadding(10, 5, 5, 5);

    final LabelField lblresulttext1 = new LabelField("Result :") {
        protected void paint(Graphics g) {
            g.setColor(0x6d6e76);

            super.paint(g);
        }
    };

    final LabelField lblresulttext2 = new LabelField(
            "Fraction Excreation of Sodium") {
        protected void paint(Graphics g) {
            g.setColor(0x6d6e76);
            super.paint(g);
        }
    };
    final LabelField lblresulttext3 = new LabelField("for this patient is") {
        protected void paint(Graphics g) {
            g.setColor(0x6d6e76);
            super.paint(g);
        }
    };

    final LabelField lblresultcal = new LabelField("") {
        protected void paint(Graphics g) {
            g.setColor(0x0AFF0A);
            super.paint(g);
        }
    };

    hfmresult.add(lblresulttext1);
    hfmresult.add(lblresulttext2);
    hfmresult.add(lblresulttext3);
    // setMargin(top,right,bottom,left)
    lblresulttext2.setMargin(5, 0, 0, 0);

    lblresulttext1.setFont(lbl.getFont().derive(Font.BOLD, 27));
    lblresulttext2.setFont(lbl.getFont().derive(Font.BOLD));
    lblresultcal.setFont(lbl.getFont().derive(Font.BOLD, 26));

    hfm8.add(hfmresult);
    hfm8.add(lblresultcal);

    // to store the Bitmap
    final HorizontalFieldManager hfmforbitmap = new HorizontalFieldManager(
            FIELD_HCENTER);
    Bitmap objimage = Bitmap.getBitmapResource("bar.png");

    // to display the Bitmap
    hfmforbitmap.add(new BitmapField(objimage));

    LabelField lbltxt3 = new LabelField(
            "Fractional Exceretion of Sodium formula ", FIELD_HCENTER) {
        protected void paint(Graphics g) {
            g.setColor(0Xde3f39);
            super.paint(g);
        }
    };

    lbltxt3.setPadding(0, 5, 5, 5);
    lbltxt3.setFont(lbl.getFont().derive(Font.BOLD, 15));

    LabelField lbltxt4 = new LabelField(
            "UNa X Pcreat / Ucreat X PNa * 100%", FIELD_HCENTER) {
        protected void paint(Graphics g) {
            g.setColor(0x6d6e76);
            super.paint(g);
        }
    };

    lbltxt4.setPadding(0, 5, 5, 5);
    lbltxt4.setFont(lbl.getFont().derive(Font.BOLD, 15));

    LabelField lbltxt5 = new LabelField("Where") {
        protected void paint(Graphics g) {
            g.setColor(0x000000);
            super.paint(g);
        }
    };

    lbltxt5.setPadding(0, 5, 5, 5);
    lbltxt5.setFont(lbl.getFont().derive(Font.BOLD, 15));

    LabelField lbltxt6 = new LabelField("UNa = Urine sodium") {
        protected void paint(Graphics g) {
            g.setColor(0x000000);
            super.paint(g);
        }
    };

    lbltxt6.setPadding(0, 5, 5, 5);
    lbltxt6.setFont(lbl.getFont().derive(Font.BOLD, 15));

    LabelField lbltxt7 = new LabelField("Pcreat = Plasma creatinine") {
        protected void paint(Graphics g) {
            g.setColor(0x000000);
            super.paint(g);
        }
    };

    lbltxt7.setPadding(0, 5, 5, 5);
    lbltxt7.setFont(lbl.getFont().derive(Font.BOLD, 15));

    LabelField lbltxt8 = new LabelField("Ucreat = Urine creatinine") {
        protected void paint(Graphics g) {
            g.setColor(0x000000);
            super.paint(g);
        }
    };

    lbltxt8.setPadding(0, 5, 5, 5);
    lbltxt8.setFont(lbl.getFont().derive(Font.BOLD, 15));

    LabelField lbltxt9 = new LabelField("PNa = Plasma sodium") {
        protected void paint(Graphics g) {
            g.setColor(0x000000);
            super.paint(g);
        }
    };

    lbltxt9.setPadding(0, 5, 5, 5);
    lbltxt9.setFont(lbl.getFont().derive(Font.BOLD, 15));

    ButtonField btn = new ButtonField("btn");

    // ///////////////////////////////////////////////////// addding all //
    // fields here

    final HorizontalFieldManager hfm_main = new HorizontalFieldManager(
            Manager.VERTICAL_SCROLL);

    final VerticalFieldManager vfm_l = new VerticalFieldManager() {
        protected void sublayout(int maxWidth, int maxHeight) {
            super.sublayout(280, maxHeight);
            setExtent(280, maxHeight);
        }

        protected void paint(Graphics g) {
            g.setBackgroundColor(Color.RED);
            // Clears the entire graphic area to the current background
            g.clear();
            super.paint(g);
        }
    };

    vfm_l.add(new LabelField("sliding pannel"));
    vfm_r.add(bmpfield1);
    vfm_r.add(hfm_mainlbltext);
    vfm_r.add(bmpfield2);

    // all layouts are added here in vertical scroll field

    mainreportfractionsodiumvfm.add(vfm_r);
    mainreportfractionsodiumvfm.add(lbltxt1);
    mainreportfractionsodiumvfm.add(lbltxt2);
    mainreportfractionsodiumvfm.add(hfm8);
    mainreportfractionsodiumvfm.add(hfmforbitmap);
    mainreportfractionsodiumvfm.add(lbltxt3);
    mainreportfractionsodiumvfm.add(lbltxt4);
    mainreportfractionsodiumvfm.add(lbltxt5);
    mainreportfractionsodiumvfm.add(lbltxt6);
    mainreportfractionsodiumvfm.add(lbltxt7);
    mainreportfractionsodiumvfm.add(lbltxt8);
    mainreportfractionsodiumvfm.add(lbltxt9);
    // mainreportfractionsodiumvfm.add(btn);
    hfm_main.add(mainreportfractionsodiumvfm);
    add(hfm_main);

1 个答案:

答案 0 :(得分:1)

如果我没记错的话,您需要在Fields上设置可关注的Manager才能滚动。

自从我做了这个黑客攻击以来已经有一段时间了,但是你能否设置一些LabelFields来获得焦点?我认为这涉及创建您自己的自定义LabelField和重写方法isFocusable()以返回true


编辑:Peter Strange是正确的 - 请按照他的建议使用NullField