簡體   English   中英

黑莓手機中的圖像拉伸問題

[英]Image stretching issue in blackberry

我正在嘗試創建一個聊天屏幕。 在該屏幕上,對於文本背景,我正在使用圖像,並根據消息文本中的字符數調整背景圖像的大小。

問題是,當字符較小時,將顯示圖像,但是當字符數量增加時,整個屏幕上的圖像將不必要地拉伸。

同樣,如果第一條消息很長,圖像將被拉伸,但是當我們發送下一個字符較小的消息時,所有背景圖像都會根據最后一條消息的大小而縮小。 屏幕快照中的前兩個消息中顯示了它。

我們可以說一行,圖像根據整個屏幕上的最后一條消息的大小進行拉伸或收縮。

在此處輸入圖片說明

白色背景的代碼在這里:

public void sendMessage(String msg) {
    HorizontalFieldManager chatHFM = new HorizontalFieldManager();

    offsets_me[2] = offsets_me[1] + msg.length();

    BitmapField bitmapField = new BitmapField(_myPic);
    bitmapField.setBorder(roundedBorder1);

    imageVFM = new VerticalFieldManager();
    imageVFM.setMargin(0,0,0,0);
    imageVFM.add(bitmapField);

    _text_Length = msg.length()+ 6;

    if(_text_Length<=60){
        if(Constants.displayWidth<=360){
            _bgImage_White = Constants.sizePic(EncodedImage.getEncodedImageResource("white_l.png"), 70, 200);
        }else if(Constants.displayWidth>360 && Constants.displayWidth<640){
            _bgImage_White = Constants.sizePic(EncodedImage.getEncodedImageResource("white_l.png"), 90, 330);
        }else if(Constants.displayWidth>=640){
            _bgImage_White = Constants.sizePic(EncodedImage.getEncodedImageResource("white_l.png"), 100, 500);
        }
    }else if(_text_Length>60 && _text_Length <=120){
        if(Constants.displayWidth<=360){
            _bgImage_White = Constants.sizePic(EncodedImage.getEncodedImageResource("white_l.png"), 140, 200);
        }else if(Constants.displayWidth>360 && Constants.displayWidth<640){
            _bgImage_White = Constants.sizePic(EncodedImage.getEncodedImageResource("white_l.png"), 170, 330);
        }else if(Constants.displayWidth>=640){
            _bgImage_White = Constants.sizePic(EncodedImage.getEncodedImageResource("white_l.png"), 200, 500);
        }
    }else if(_text_Length>120 && _text_Length<200){
        if(Constants.displayWidth<=360){
            _bgImage_White = Constants.sizePic(EncodedImage.getEncodedImageResource("white_l.png"), 200, 200);
        }else if(Constants.displayWidth>360 && Constants.displayWidth<640){
            _bgImage_White = Constants.sizePic(EncodedImage.getEncodedImageResource("white_l.png"), 240, 330);
        }else if(Constants.displayWidth>=640){
            _bgImage_White = Constants.sizePic(EncodedImage.getEncodedImageResource("white_l.png"), 270, 500);
        }
    }

    textVFM = new VerticalFieldManager(){
        protected void paint(Graphics graphics) {
            graphics.drawBitmap(0,0 , _bgImage_White.getWidth() , getHeight(), _bgImage_White, 0, 0);
            super.paint(graphics);
        }
    };

    EditField richTextField = new EditField("" ,"" ,140, 0L){ 
        protected void paint(Graphics graphics) {
            graphics.setColor(Color.RED);
            super.paint(graphics);
        }
        public void layout (int width, int height) {
            super.layout (width, height);
            if (getExtent().height < _bgImage_White.getHeight()){
                setExtent (width, _bgImage_White.getHeight());
            }else{setExtent (width, _bgImage_White.getHeight());}

        }
    };
    //  richTextField.setBorder(roundedBorder1);
    richTextField.setText("Me : "+msg);
    richTextField.setEditable(false);
    richTextField.setMargin(10,10,10,10);
    textVFM.add(richTextField);
    textVFM.setMargin(0,75,0,0);
    chatHFM.add(imageVFM);
    chatHFM.add(textVFM);
    chatHFM.setMargin(8,0,8,0);
    this.add(chatHFM);
    this.add(new NullField(NullField.FOCUSABLE));    
}

從以下鏈接下載高級UI代碼:

進階使用者介面

運行並檢查UIExampleNegativeMarginScreen類。

我認為它將為您提供幫助。

Advanced UI組件的實現

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM