黑莓APplication在PORSCHE手机上无法很好地呈现

时间:2013-11-13 12:20:09

标签: user-interface blackberry

我有一个Blackberry本机应用程序,我在过去几周一直在研究。 基本上它由几个屏幕组成,我可以通过覆盖FieldManagers的绘制方法来绘制我的屏幕设计 我已经测试了黑莓4.5和其他黑莓的 到目前为止,它一直很顺利,直到我遇到黑莓保时捷版本的故障测试 这不能很好地展现我的设计。我所经历的是,在滚动时,我的屏幕被擦掉了。 请允许这里的任何人在过去经历过这样的问题,原因是什么。我愿意展示代码的各个部分,以深入了解我遇到的问题。至少我提到它在没有这些问题的模拟器上显示良好。

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

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);


}

1 个答案:

答案 0 :(得分: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());
        }
    };

在这种情况下,您要求父母经理自行解决并给出具体的尺寸。执行此操作时,您需要确保给予父类的大小不大于给定的大小,因此编写类似的代码更为正确:

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

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

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

现在有一个VerticalFieldManager认为它工作在一定的大小,并且会围绕这个大小优化它的绘画,你可能会给它一个不同的大小。这可能会混淆!

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

换句话说,如果你要让超类布局字段,那么让超类设置大小,否则事情可能会混淆。

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

   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()处理来执行此操作,然后,一旦完成它,你突然说实际上,我想在Field上有一些边距。再次,您可能会混淆处理 - 在布置字段的过程中,您正在更改与放置字段相关的因素之一...

我建议您查看有关创建Managers(以及可能是Fields)的文档,并查看删除任何破坏此过程的代码。为了帮助您进行此调查,我建议您从这里开始:

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

paint()中的一般规则是不要更改Field,只绘制其当前内容。

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

1)经常调用paint()。你真的想最大限度地减少在油漆中完成的处理。因此,每次浏览时都不要创建图像(请参阅上面代码中的左图)。创建一次,然后使用paint绘制()图像。在油漆中做过多的工作会导致性能问题以及杀死电池。这是您在模拟器上不会注意到的事情,因为它与设备相比速度非常快。

2)请注意,使用invalidate()时的想法是重新绘制Field。所以没有必要在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()之前纠正错误。