开发者

Blackberry: WebBitmapField center image

开发者 https://www.devze.com 2023-02-05 23:45 出处:网络
http://www.coderholic.com/blackberry-webbitmapfield/ This is a great script for grabbing an image from the web for a Blackberry App. Now I would like to know how to center the returned image. I have

http://www.coderholic.com/blackberry-webbitmapfield/

This is a great script for grabbing an image from the web for a Blackberry App. Now I would like to know how to center the returned image. I have tried everything.

This portion of code seems to return the image:

byte[] dataArray = data.getBytes();

bitmap = EncodedImage.createEncodedImage(dataArray, 0,

dataArray.length);

setImage(bitmap);

This displays the image:

getimage = new Web开发者_StackOverflow社区BitmapField("http://"); add (getimage);

Where can I put FIELD_HCENTER to center this thing. Please show sample code. Thanks!!


If you insist on using this WebBitmapField, then you'll need to add a new constructor so that style bits can be passed to the BitmapField:

public class WebBitmapField extends BitmapField implements WebDataCallback  
{  
    ...
    public WebBitmapField(String url, long style)  
    {  
        super(style);
        try  
        {  
            Util.getWebData(url, this);  
        }  
        catch (Exception e) {}  
    }  

    public WebBitmapField(String url) 
    {
        this(url, 0L);
    }
    ...
}


If you place your WebBitmapField in a custom manager and set the position of the field then u can possibly achieve the center location like:

class CustomManager extends Manager
{
    CustomManager()
     {
        super(Manager.USE_ALL_WIDTH);
     } 
    sublayout(int width , int height)
     {
       Field field = getField(0);
       layoutChild(field , Display.getWidth(), Display.getHeight());
       setPositionChild(field, (Display.getWidth()- field.getWidth())/2,
           Display.getHeight());

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


In MainScreen use it as:
CustomManager  obj = new CustomManager();
getimage = new WebBitmapField("http://");
obj.add(getimage );
add(obj);
0

精彩评论

暂无评论...
验证码 换一张
取 消