繁体   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