Blackberry BrowserField does not fit to screen

允我心安 提交于 2019-12-11 06:59:35

问题


I'm trying to display a website inside my blackberry app but the browserfield is smaller than the screen height and i can`t make it the same size.

The page that is beeing loaded is actually smaller then the screen but the website is designed for mobile devices and fits perfectly on iphone webview, blabkberry browser and firefox and chrome.

My code is the following:

    manager = new VerticalFieldManager(VerticalFieldManager.VERTICAL_SCROLL | VerticalFieldManager.HORIZONTAL_SCROLL)
    {
        protected void sublayout(int maxWidth, int maxHeight)
        {
            super.sublayout(maxWidth, maxHeight);
            setExtent(Display.getWidth(), Display.getHeight());
        }
    };
    manager.setBackground(BackgroundFactory.createSolidBackground(Color.RED));

    BrowserFieldConfig myBrowserFieldConfig = new BrowserFieldConfig();

    myBrowserFieldConfig.setProperty(BrowserFieldConfig.ALLOW_CS_XHR, Boolean.TRUE);
    myBrowserFieldConfig.setProperty(BrowserFieldConfig.JAVASCRIPT_ENABLED, Boolean.TRUE);
    myBrowserFieldConfig.setProperty(BrowserFieldConfig.INITIAL_SCALE, new Float(1));

    browserField = new BrowserField(myBrowserFieldConfig);
    browserField.requestContent(link);

    manager.add(browserField);

The effect that I get is the following: when i load this screen the hole screen is red (the manager background). After that the screen turns white (i think this is the browserfield) and then when the webpage is loaded the screen turns red again and the white piece shrinks to a line height and grows as the webpage ellements starts to show. The problem is that the page should fit all the screen as it does in iphone and custom browsers.

OBS: I'm using blackberry OS version 6


回答1:


I don't know if my solution would help you but I faced exactly the same issue as yours,after spending hours on it I finally fixed it by adding the following line in the header section of my html page:

<meta name="viewport" content="width=device-width,height=device-height,minimum-scale=1, maximum-scale=1" />

Height=device-height fixed my issue




回答2:


This code in html:
<meta name="viewport" content="width=device-width,height=device-height,minimum-scale=1, maximum-scale=1" />
can be replaced with this on client:

config = new BrowserFieldConfig();
  config.setProperty(BrowserFieldConfig.VIEWPORT_WIDTH, new Integer(
            Display.getWidth()));
    config.setProperty(BrowserFieldConfig.INITIAL_SCALE, new Float(1.0));

    config.setProperty(BrowserFieldConfig.USER_SCALABLE, Boolean.FALSE);

    browserField = new BrowserField(config);



回答3:


Try like this:

protected void sublayout(int maxWidth, int maxHeight)
{
     super.sublayout(Display.getWidth(), Display.getHeight());
     setExtent(Display.getWidth(), Display.getHeight());
}



回答4:


try in sublayout passing Display.getHeight() instead f maxHeight




回答5:


try this

   class MyFieldManager extends VerticalFieldManager
    {

    int width;
    int height;

    MyFieldManager(int w,int h)

    {
        super(Manager.VERTICAL_SCROLL | Manager.HORIZONTAL_SCROLL );
        width=w;
        height=h;
    }

    public void    sublayout(int w,int h)
    {
        super.sublayout(w, h);
        setExtent(width,height);
    }
}

    BrowserFieldConfig config = new BrowserFieldConfig();  
    config.setProperty(BrowserFieldConfig.ALLOW_CS_XHR, Boolean.TRUE);  
    config.setProperty(BrowserFieldConfig.INITIAL_SCALE, new Float(0.5));
    MyFieldManager m=new MyFieldManager(Display.getWidth()/2,Display.getHeight()/2);
    add(m);
    BrowserField _browserField = new BrowserField(config);
    _browserField.addListener(new InnerBrowserListener());
    m.add(_browserField);


来源:https://stackoverflow.com/questions/8539285/blackberry-browserfield-does-not-fit-to-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!