简体   繁体   中英

Blackberry: WebBitmapField center image

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 WebBitmapField("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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM