0

我有一个过去几周一直在开发的黑莓原生应用程序。基本上它由几个屏幕组成,在这些屏幕中,我可以通过覆盖我在黑莓 4.5 和其他黑莓上测试过的 FieldManager 的绘制方法来绘制我的屏幕设计。
到目前为止,它的渲染效果很好,直到我在黑莓的保时捷版本上进行了一次故障测试,这并不能很好地渲染我的设计。我的经验是,在滚动时,我的屏幕会被擦除。请问这里有没有人过去遇到过这样的问题,原因是什么。我愿意展示代码的各个部分,以深入了解我遇到的问题。至少我提到它在没有这些问题的情况下在模拟器上显示良好。

我发布了一个示例屏幕,这是我的登录屏幕:

final VerticalFieldManager everythingPanel = new VerticalFieldManager(VERTICAL_SCROLL)
    {
        public void paint(Graphics graphics)
        {
            graphics.setBackgroundColor(new UtilNew().ashbrand);
            graphics.clear();
            super.paint(graphics);
        }
        public void sublayout(int width, int height){

            super.sublayout(Display.getWidth(),Display.getHeight());
            setExtent(Display.getWidth(), Display.getHeight());
        }
    };


    final VerticalFieldManager spaceHolder1 = new VerticalFieldManager()
    {
        public void paint(Graphics graphics)
        {
            graphics.setBackgroundColor(new Util().ashbrand);
            graphics.clear();
            super.paint(graphics);
        }


        public void sublayout(int width, int height){
            super.sublayout(Display.getWidth(),topSpaceHeight);
            setExtent(Display.getWidth(), topSpaceHeight);
        }
    };




    final VerticalFieldManager contentHolderPix = new VerticalFieldManager(VerticalFieldManager.VERTICAL_SCROLL)
    {
        public void paint(Graphics graphics)
        {


            graphics.setBackgroundColor(util.ashbrand);//black
            graphics.setColor(new Util().whitebrand);
            System.out.println(">>>>!!!!>>>>" + "img/icons/logo" + new Util().getResource() + ".png");
            EncodedImage image_1 = EncodedImage.getEncodedImageResource("img/icons/icon" + new Util().getResource() + ".png");

            setFont(util.initializeUtilFont("Arial", editFieldFontHeaderSize, Font.BOLD));
            int startHere = topSpaceHeight - image_1.getHeight() - 5;
            int imageWidth1 = (int)((Display.getWidth() - image_1.getWidth() - getFont().getAdvance("Sign In"))/2);
            graphics.drawBitmap(new XYRect(imageWidth1 - 10 - whiteBgEdge.left - whiteBgEdge.right, startHere, image_1.getWidth(), image_1.getHeight()), image_1.getBitmap(), 0, 0);
            int startfonty = startHere + ((image_1.getHeight() - getFont().getHeight())/2);

            graphics.drawText("Sign In", imageWidth1, startfonty);
            super.paint(graphics);

        }


        public void sublayout(int width, int height){
            super.sublayout(whiteBgWidth,topSpaceHeight);
            setExtent(whiteBgWidth, topSpaceHeight);
            setMargin(whiteBgEdge);
        }
    };



    System.out.println("whiteBgWidth>>>>" + whiteBgWidth); 
    System.out.println("padExtWhiteBg>>>>" + padExtWhiteBg);


    usernameField = utilNew.newEditTextField(editFieldWidth, editFont.getHeight(), 30, 
            EditField.NO_NEWLINE, "", editFieldPad, editFont, false, "Username");
    passwordField = utilNew.newPasswordField(editFieldWidth, editFont.getHeight(), 30, 
            PasswordEditField.NO_NEWLINE,       "Password", editFieldPad, editFont);
    //usernameField.setMargin(holderPad1);
    if(user_!=null && user_.getSignInUserName()!=null && user_.getSignInUserName().trim().length()>0)
        usernameField.setText(user_.getSignInUserName());

    final int edHt = editFont.getHeight() + editFieldPad.top + editFieldPad.bottom;
    final int edWt = editFieldWidth +  editFieldPad.left + editFieldPad.right;
    System.out.println("edHt = " + edHt);
    System.out.println("edWt = " + edWt);
    System.out.println("HolderPad1 = " + holderPad1.top + ",  " + holderPad1.bottom + ",  " + holderPad1.left + ",  " + holderPad1.right);
    usernameFieldHolder = utilNew.generateEditTextField(usernameField, true, holderPad1, edHt, edWt, true);
    passwordFieldHolder = utilNew.generateEditTextField(passwordField, true, holderPad2, edHt, edWt, false);


    final int height_ = edHt + edHt + holderPad1.top + holderPad1.bottom + holderPad2.top + holderPad2.bottom + 20;
    System.out.println("height___>>>>>" + height_);


    final VerticalFieldManager contentHolder1 = new VerticalFieldManager()
    {
        public void paint(Graphics graphics)
        {


            //System.out.println(edHt + "," + edHt + "," + holderPad1.top + "," + holderPad1.bottom + "," + holderPad2.top + "," + holderPad2.bottom);
            graphics.setBackgroundColor(util.ashbrand);//black

            graphics.setColor(new Util().whitebrand);
            graphics.drawRoundRect(0, 0, whiteBgWidth, height_, 20, 20);
            graphics.fillRoundRect(0, 0, whiteBgWidth, height_, 20, 20);
            graphics.setColor(0x00808080);
            //System.out.println("This is changed?");
            //System.out.println("<<<<<<.." + usernameFieldHolder.getPreferredHeight() + "hfm.getPreferredHeight() = 0" + usernameFieldHolder.getWidth() );
            //graphics.drawLine(40, usernameField.getPreferredHeight(), whiteBgWidth, usernameField.getPreferredHeight());/**/
            super.paint(graphics);

        }


        public void sublayout(int width, int height){

            System.out.println(Display.getHeight()  + " - " + Display.getWidth());
            System.out.println("Wdith & height = " + width  + " && " + height);
            System.out.println("Wdith & this.getPreferredHeight() = " + this.getWidth()  + " && " + this.getHeight());
            super.sublayout(whiteBgWidth,height_);
            setExtent(whiteBgWidth, height_);
            setMargin(whiteBgEdge);
        }
    };


    int buttonHeight = 70;

    /*CustomManager hfm_buttons = util.generateHFM1(
            contentHolder1.getPreferredWidth(), 
            buttonHeight, 
            new Util().whitebrand,
            0);*/
    //submitButton = new UtilNew().generateButtonField(0x333333, util.whitebrand,   "LOGIN", null);
    //registerButton = new UtilNew().generateButtonField(0x333333, util.whitebrand,     "REGISTER", null);


    final LabelField loginButton = new LabelField("", Field.FOCUSABLE)
    {

        private int hColor;

        public boolean isFocusable() {
            return true;
        }

        protected void drawFocus(Graphics g, boolean on){
            XYRect rect = new XYRect();
            getFocusRect(rect);
            drawHighlightRegion(g, HIGHLIGHT_FOCUS, false, rect.x, rect.y, rect.width, rect.height);
        }


        public void paint(Graphics g)
        {
            EncodedImage left;
            EncodedImage right;
            EncodedImage center;

            if(isFocus())
            {
                left = EncodedImage.getEncodedImageResource("img/buttons/left.png");
                center = EncodedImage.getEncodedImageResource("img/buttons/center.png");
                right = EncodedImage.getEncodedImageResource("img/buttons/right.png");
                g.setColor(util.green);
                hColor = 0xcccccc;
            }
            else
            {
                left = EncodedImage.getEncodedImageResource("img/buttons/_left.png");
                center = EncodedImage.getEncodedImageResource("img/buttons/_center.png");
                right = EncodedImage.getEncodedImageResource("img/buttons/_right.png");
                g.setColor(util.greenDark);
                hColor = util.ashbrand;
            }
            //g.fillRect(0, 0, getPreferredWidth(), getPreferredHeight());
            int totalWidth = whiteBgWidth + 4;
            XYRect left_edge=new XYRect(2, 2, left.getWidth(), left.getHeight());


            g.drawBitmap(left_edge, left.getBitmap(), 0, 0);
            //invalidate();
            int startX= (Display.getWidth() - totalWidth)/2;
            int vount = (int)((totalWidth - left.getWidth() - right.getWidth())/center.getWidth()) - 3;
            //System.out.println("vount = " + vount);
            int widthbt = 0;
            for(int c=0; c<vount; c++)
            {
                widthbt = left.getWidth() + (c*center.getWidth())+2;
                XYRect center_edge=new XYRect(widthbt, 2, center.getWidth(), center.getHeight());
                g.drawBitmap(center_edge, center.getBitmap(), 0, 0);
            }
            XYRect right_edge=new XYRect(widthbt,2, right.getWidth(), right.getHeight());
            g.drawBitmap(right_edge, right.getBitmap(), 0, 0);
            //invalidate();
            //g.drawBitmap(right_edge, right.getBitmap(), 0, 0);
            //g.fillRect(left_edge.getWidth(), 0, getPreferredWidth(), getPreferredHeight());
            int colorOld = g.getColor();
            g.setColor(hColor);
            g.drawRoundRect(0, 0, totalWidth-4, left.getHeight()+4, 3, 3);
            g.setColor(colorOld);

            if(isFocus())
            {
                g.setColor(util.black);
            }
            else
            {
                g.setColor(util.whitebrand);
            }

            int height = (left.getHeight() - getFont().getHeight())/2;
            int width = (totalWidth - getFont().getAdvance("Sign In"))/2;
            g.drawText("Sign In", width, height);
            setExtent(totalWidth+ 5,left.getHeight() + 10);
            //setMargin(new XYEdges(20, 10, 0, whiteBgEdge.left));
            invalidate();
            super.paint(g);
        }

        public int getPreferredHeight() {
            return getFont().getHeight() + 20;
        }

        public int getPreferredWidth() {
            return (int)(whiteBgWidth);
        }

        protected boolean navigationClick(int status, int time) {

            removeAllMenuItems();
            String userName = usernameField.getText().toString().toLowerCase();
            user_.setSignInUserName(userName);
            String passWord = passwordField.getText().toString();
            System.out.println("username = " + userName + " & password = " + passWord);
            User user = User.getInstance();
            System.out.println(">>instance of user from sign in: " + user);
            Records record = new Records();

            if(passWord.trim().length() < 2 || userName.trim().length() < 2){
                Dialog.alert("Invalid username and/or password entered");
                SignIn screen = new SignIn();
                ScreenController screenController = ScreenController.getInstance();
                screenController.addNewScreen(screen);
            }else{
                System.out.println("else if data is calid");
                String hashPassword = user.md5Java(passWord);
                hashPassword = "e86e107b113b0f830b9b817b4a9addb8";
                user_.setUserName(userName);
                user_.setPassword(passWord);

                System.out.println("Check data availability");
                try 
                {    
                     FileConnection fc = (FileConnection)Connector.open(utilNew.FOLDER_LOCATION);
                     FileConnection fc1 = (FileConnection)Connector.open(utilNew.FOLDER_LOCATION_REF);
                     if (!fc.exists())
                     {
                         fc.mkdir(); 
                         if (!fc1.exists())
                         {
                             fc.mkdir(); 
                         }
                     }
                     fc.close();
                 }
                 catch (IOException ioe) 
                 {
                    System.out.println(ioe.getMessage() );
                 }

                if((record.isDataAvailable(record.userTable)==true))
                {
                    System.out.println(">>>>@@@ -1 ");
                    String[] allRecords = record.getAllRecords(record.userTable);
                    boolean proceedYes = true;
                    int count = 0;
                    while(proceedYes && count<allRecords.length)
                    {
                        System.out.println(">>>> Record = " + allRecords[count]);
                        //Dialog.alert(">>>> Record = " + allRecords[count]);
                        DataInputStream is = new DataInputStream(new ByteArrayInputStream(allRecords[count].getBytes()));
                        try {
                            System.out.println(">>>>555");
                            //System.out.println(">>>>" + is.readUTF() + " && " + is.readUTF() + " && " + is.readUTF());
                            String l = is.readUTF();
                            String u = is.readUTF();
                            String p = is.readUTF();
                            //System.out.println("e>>>>" + is.readUTF() + " && " + is.readUTF() + " && " + is.readUTF());
                            System.out.println("f>>>>" + l + " && " + u + " && " + p);
                            System.out.println("g>>>>" + userName + " && " + passWord + " && " + p);
                            if(u.equals(userName) && p.equals(passWord))
                            {
                                //Dialog.alert(">>>>12");
                                System.out.println(">>>889948444>");

                                proceedYes = false;

                                MenuLists screen = new MenuLists(10);
                                //UiApplication.getUiApplication().pushScreen(homeScreen);
                                ScreenController screenController = ScreenController.getInstance();
                                screenController.setCurrentScreen(SignIn.this);
                                screenController.addNewScreen(screen);
                            }
                        } catch (IOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                            System.out.println(">>>>Error " + e.getMessage() + " && " + e.toString() );
                        }
                        count++;
                    }



                    if(proceedYes)
                    {

                        System.out.println(">>>>@@@ 3 ");
                        Hashtable jj = new Hashtable();
                        boolean proceedNow = false;

                        jj.put("username", userName);
                        jj.put("password", passWord);
                        jj.put("url", "https://localhost:8080/signinws/rest/account/login2");
                        System.out.println("object sent to server: "+jj);


                        ProcessAction processAction = new ProcessAction(jj, 0, record);
                        PopUpScreen.showScreenAndWait(processAction, "Setting up our account. Please Wait");


                    }
                }
                else
                {

                    System.out.println(">>>>@@@ o ");
                    Hashtable jj = new Hashtable();
                    boolean proceedNow=false;

                    System.out.println(">>>>@@@ 4 ");
                    jj.put("username", userName);
                    jj.put("password", passWord);
                    jj.put("url", "https://localhost:8080/signinws/rest/account/login2");

                    System.out.println("object sent to server: "+jj);
                    proceedNow = true;
                    ProcessAction processAction = new ProcessAction(jj, 0, record);
                    PopUpScreen.showScreenAndWait(processAction, "Please Wait");

                }

            }
            return super.navigationClick(status, time);
        }
    };


    final LabelField registerButton = new LabelField("", Field.FOCUSABLE)
    {

        public boolean isFocusable() {
            return true;
        }

        protected void drawFocus(Graphics g, boolean on){
            XYRect rect = new XYRect();
            getFocusRect(rect);
            drawHighlightRegion(g, HIGHLIGHT_FOCUS, false, rect.x, rect.y, rect.width, rect.height);
        }


        public void paint(Graphics g)
        {
            EncodedImage left;
            EncodedImage right;
            EncodedImage center;
            int hColor;

            if(isFocus())
            {
                left = EncodedImage.getEncodedImageResource("img/buttons/left.png");
                center = EncodedImage.getEncodedImageResource("img/buttons/center.png");
                right = EncodedImage.getEncodedImageResource("img/buttons/right.png");
                g.setColor(util.green);
                hColor = 0xcccccc;
            }
            else
            {
                left = EncodedImage.getEncodedImageResource("img/buttons/_left.png");
                center = EncodedImage.getEncodedImageResource("img/buttons/_center.png");
                right = EncodedImage.getEncodedImageResource("img/buttons/_right.png");
                g.setColor(util.greenDark);
                hColor = util.ashbrand;
            }
            //g.fillRect(0, 0, getPreferredWidth(), getPreferredHeight());
            int totalWidth = whiteBgWidth + 4;
            XYRect left_edge=new XYRect(2, 2, left.getWidth(), left.getHeight());

            g.drawBitmap(left_edge, left.getBitmap(), 0, 0);
            //invalidate();
            int startX= (Display.getWidth() - totalWidth)/2;
            int vount = (int)((totalWidth - left.getWidth() - right.getWidth())/center.getWidth()) - 3;
            XYRect left_edgeH=new XYRect(0, 0, vount, left.getHeight()+2);
            //System.out.println("vount = " + vount);
            int widthbt = 0;
            for(int c=0; c<vount; c++)
            {
                widthbt = left.getWidth() + (c*center.getWidth()) + 2;
                XYRect center_edge=new XYRect(widthbt, 2, center.getWidth(), center.getHeight());
                g.drawBitmap(center_edge, center.getBitmap(), 0, 0);
            }
            XYRect right_edge=new XYRect(widthbt,2, right.getWidth(), right.getHeight());
            g.drawBitmap(right_edge, right.getBitmap(), 0, 0);
            //invalidate();
            //g.drawBitmap(right_edge, right.getBitmap(), 0, 0);
            //g.fillRect(left_edge.getWidth(), 0, getPreferredWidth(), getPreferredHeight());
            int colorOld = g.getColor();
            g.setColor(hColor);
            g.drawRoundRect(0, 0, totalWidth-4, left.getHeight()+4, 3, 3);
            g.setColor(colorOld);

            if(isFocus())
            {
                g.setColor(util.black);
            }
            else
            {
                g.setColor(util.whitebrand);
            }

            int height = (left.getHeight() - getFont().getHeight())/2;
            int width = (totalWidth - getFont().getAdvance("Create An Account"))/2;
            g.drawText("Create An Account", width, height);
            setExtent(totalWidth + 5,left.getHeight() + 10);
            setPosition(0, getFont().getHeight() + 30);
            invalidate();
            super.paint(g);
        }

        public int getPreferredHeight() {
            return getFont().getHeight() + 20;
        }

        public int getPreferredWidth() {
            return (int)(whiteBgWidth);
        }

        protected boolean navigationClick(int status, int time) {
            removeAllMenuItems();
            RegisterScreen registerScreen = new RegisterScreen();
            ScreenController screenController = ScreenController.getInstance();
            screenController.addNewScreen(registerScreen);
            return super.navigationClick(status, time);
        }
    };


    final VerticalFieldManager spaceHolder2 = new VerticalFieldManager(NO_VERTICAL_SCROLL | NO_HORIZONTAL_SCROLL)
    {
        public void paint(Graphics graphics)
        {
            graphics.setBackgroundColor(utilNew.ashbrand);
            graphics.clear();
            super.paint(graphics);
        }


        public void sublayout(int width, int height){
            int w = whiteBgWidth;
            super.sublayout(w, (loginButton.getPreferredHeight() * 2) + 40);
            setExtent(w, (loginButton.getPreferredHeight() * 2) + 40);
            int startX = (int)((Display.getWidth() - whiteBgWidth)/2);
            setMargin(new XYEdges(20, 0, 0, startX));
        }
    };
    spaceHolder2.add(loginButton);
    spaceHolder2.add(registerButton);
    //spaceHolder2.add(registerButton);


    spaceHolder1.add(contentHolderPix);
    everythingPanel.add(spaceHolder1);
    contentHolder1.add(usernameFieldHolder);
    contentHolder1.add(passwordFieldHolder);





    /*passwordFieldDummyHolder.setFocusListener(new FocusChangeListener(){

        public void focusChanged(Field field, int eventType) {
            // TODO Auto-generated method stub
            if(eventType == FocusChangeListener.FOCUS_GAINED)
            {
                contentHolder1.replace(passwordFieldDummyHolder, passwordFieldHolder);
            }
        }

    });

    passwordFieldHolder.setFocusListener(new FocusChangeListener(){

        public void focusChanged(Field field, int eventType) {
            // TODO Auto-generated method stub
            if(eventType == FocusChangeListener.FOCUS_LOST)
            {
                System.out.println(">>>>>|>>>" + passwordFieldHolder.getIndex());
                System.out.println(">>>>>|>>>" + passwordFieldDummyHolder.getIndex());
                if(passwordField.getText().length()==0)
                {
                    System.out.println(">>>>>1>>>");
                    passwordFieldDummyHolder = utilNew.generateEditTextField(passwordFieldDummy, true, holderPad2, edHt, edWt, false);
                    contentHolder1.replace(passwordFieldHolder, passwordFieldDummyHolder);
                    //loginButton.setFocus();
                }
                System.out.println(">>>>>2>>>");
                System.out.println(">>>>>2>>>");
            }
        }


    });*/





    everythingPanel.add(contentHolder1);
    everythingPanel.add(spaceHolder2);
    add(everythingPanel);


}
4

1 回答 1

0

我不知道您的问题实际上是什么,但从我在您的示例代码中看到的内容很明显,您正在以不正确的方式使用 UI 框架。在继续之前,您需要解决这些问题。

这是一个例子:

final VerticalFieldManager everythingPanel = new VerticalFieldManager(VERTICAL_SCROLL)
    {
        public void paint(Graphics graphics)
        {
            graphics.setBackgroundColor(new UtilNew().ashbrand);
            graphics.clear();
            super.paint(graphics);
        }
        public void sublayout(int width, int height){

            super.sublayout(Display.getWidth(),Display.getHeight());
            setExtent(Display.getWidth(), Display.getHeight());
        }
    };

在这种情况下,您要求父 Manager 对其进行布局并为其指定特定大小。执行此操作时,您需要确保为父类提供的大小不大于您给定的大小,因此编写如下代码更正确:

super.sublayout(Math.min(Display.getWidth(), width),Math.min(Display.getHeight(), height));

这将尝试在您告诉它使用的屏幕空间范围内(在本例中为屏幕大小)对包含在管理器中的字段进行布局。完成此操作后,它将设置它需要的实际大小 - 换句话说,在布局方法结束时,VerticalFieldManager 将知道它需要多大并设置该大小。然后它返回。然后你这样做:

setExtent(Display.getWidth(), Display.getHeight());

实际上,现在您有一个 VerticalFieldManager,它认为它正在以特定尺寸工作,并将围绕该尺寸优化其绘画,并且您可能已赋予它不同的尺寸。这可能会混淆!

同样的注释也适用于 Field 的 layout() 方法。

换句话说,如果你要让超类来布局Fields,那就让超类来设置大小,否则事情会很混乱。

这是另一个实际上更糟糕的示例:

   final VerticalFieldManager spaceHolder2 = new VerticalFieldManager(NO_VERTICAL_SCROLL | NO_HORIZONTAL_SCROLL)
    {
        public void paint(Graphics graphics)
        {
            graphics.setBackgroundColor(utilNew.ashbrand);
            graphics.clear();
            super.paint(graphics);
        }


        public void sublayout(int width, int height){
            int w = whiteBgWidth;
            super.sublayout(w, (loginButton.getPreferredHeight() * 2) + 40);
            setExtent(w, (loginButton.getPreferredHeight() * 2) + 40);
            int startX = (int)((Display.getWidth() - whiteBgWidth)/2);
            setMargin(new XYEdges(20, 0, 0, startX));
        }
    };

为什么这更糟?因为这条线:

setMargin(new XYEdges(20, 0, 0, startX));

请记住,子布局的重点是将所有字段放置在屏幕上。您已经调用了 super.sublayout() 处理来执行此操作,然后,一旦完成,您实际上突然说,我想要在字段上留一些边距。再次,您可能会混淆处理 - 在布置字段的中间,您正在更改与布置字段相关的因素之一......

我建议您查看有关创建管理器(可能还有字段)的文档,并删除任何破坏此过程的代码。为了协助您进行这项调查,我建议您从这里开始:

http://supportforums.blackberry.com/t5/Java-Development/MainScreen-explained/ta-p/606644

然后看看这些:

http://supportforums.blackberry.com/t5/Java-Development/How-to-Extend-the-Screen/ta-p/446745

http://supportforums.blackberry.com/t5/Java-Development/How-to-Extend-the-Screen/ta-p/446745

http://supportforums.blackberry.com/t5/Java-Development/Create-a-custom-layout-manager-for-a-screen/ta-p/442990

http://supportforums.blackberry.com/t5/Java-Development/Create-custom-fields/ta-p/444962

你在你的绘画程序中做类似的事情。这是一个片段:

            public void paint(Graphics g)
            {
                EncodedImage left;
                EncodedImage right;   
...
               left = EncodedImage.getEncodedImageResource("img/buttons/left.png");
...
                setExtent(totalWidth + 5,left.getHeight() + 10);
                setPosition(0, getFont().getHeight() + 30);
                invalidate();
                super.paint(g);
            }

paint() 的工作是绘画,而不是定位。您的代码应该在您的布局(或子布局)处理中定位字段。但是在上面的代码中,您可能会在尝试绘制字段时移动并更改字段的大小!!!!这势必会给系统带来一些问题。

paint() 中的一般规则是您不更改字段,您只需绘制其当前内容。

关于上面给出的 paint() 代码,我将评论另外两件事。

1)paint() 经常被调用。你真的想尽量减少在油漆中完成的处理。所以不要在每次浏览时都创建一个图像(参见上面包含的代码中的左图)。创建一次,然后使用paint 来绘制()图像。在油漆中做过多的工作会导致性能问题以及耗尽电池。这是您在模拟器上不会注意到的那种事情,因为它与设备相比是如此之快。

2) 请注意,使用 invalidate() 时的想法是重新绘制字段。所以在paint()的中间调用invalidate()是没有意义的。事实上,这样做会导致无限循环。每次调用paint() 时,您的代码都会使用invalidate() 来要求Field 重新绘制自身,这会导致paint() 被调用,从而要求invalidate(),......你明白了!

我已经指出了您的布局处理和绘画处理中的问题。我并不是说这些问题实际上直接给了你你看到的问题。可能是别的东西。您为我提供了太多代码来查看所有代码以寻找那根针。如果您希望我们详细审查代码,那么我建议您使用较小的代码示例重新创建问题。事实上,我建议您尝试这样做,因为通过删除代码直到问题消失,您会发现问题的真正原因。

最后还有几点:

A) 在paint() 或paintBackground() 中进行背景绘制没有真正的区别。事实上,你似乎做的唯一背景画是这样的:

        graphics.setBackgroundColor(new UtilNew().ashbrand);
        graphics.clear();

这在paint() 中绝对没问题,我不会费心将其更改为使用paintBackground() 或Background 类。我对这段代码的一个问题是,每次调用paint 时都会创建一个新的UtilNew 类实例(很多)。这对性能没有帮助。

B)我会避免在滚动更改侦听器中调用 Screen.invalidate() ,直到您确定没有其他方法可以正确绘制屏幕。如前所述,您提供的内容中还有许多其他可疑代码。在尝试 Screen.invalidate() 之前更正它。

于 2013-11-18T10:39:48.207 回答