2013-01-24 115 views
1

我有一个背景图像,并覆盖2个LabelFields,一个BasicEditField和一个ButtonField覆盖在一个屏幕上。我的问题是我的背景图像在按钮底部后切断,而不是完全填满屏幕。 (我删除多余的代码,为了便于阅读)如何完全设置背景图像填充屏幕?

VerticalFieldManager bgManager = new VerticalFieldManager(Manager.USE_ALL_WIDTH | 
                   Manager.NO_VERTICAL_SCROLL | 
                   Manager.NO_VERTICAL_SCROLLBAR) { 

     //Override the paint method to draw the background image. 
     public void paint(Graphics graphics) 
     { 
      //Draw the background image and then call super.paint 
      //to paint the rest of the screen. 
      graphics.drawBitmap(0, 0, Display.getWidth(), Display.getHeight(), backgroundBitmap, 0, 0); 
      super.paint(graphics); 
     } 
    }; 
    this.add(bgManager); 

    LabelField header = new LabelField("", LabelField.USE_ALL_WIDTH | DrawStyle.HCENTER); 
    header.setText("Search by Drug Name"); 
    bgManager.add(header); 

    LabelField subtitle = new LabelField("", LabelField.USE_ALL_WIDTH | DrawStyle.HCENTER); 
    subtitle.setText("(brand name or generic)"); 
    bgManager.add(subtitle); 

    HorizontalFieldManager hfm = new HorizontalFieldManager(); 

    final BasicEditField edit = new BasicEditField("", "", 50, EditField.EDITABLE | BasicEditField.NO_NEWLINE) { 
     //code to make background of text box white 
     } 
    }; 
    hfm.add(edit); 

    ButtonField search = new ButtonField("Search"); 
    search.setChangeListener(new FieldChangeListener() { 

     public void fieldChanged(Field field, int context) { 
      //do something 
     } 
    }); 

我的背景图片完全填满屏幕,如果我添加Manager.USE_ALL_HEIGHTbgManager,但后来我的整个屏幕变成滚动无限。如果没有Manager.USE_ALL_HEIGHT,我的屏幕根本无法滚动(正确),但背景图像在内容结束时被切断。

我该如何构建这个屏幕,以便它不滚动,并具有占用整个可见屏幕的背景图像?

这里是什么样子错误:

enter image description here

这里是什么样子正确的(但卷轴不正确地):

enter image description here

这里的背景图片我使用:

enter image description here

+0

所以你的屏幕**以前**允许任何垂直滚动? – Nate

+0

为了简单起见,没有。我只需要图像填充屏幕并禁用滚动(无论是使用轨迹球还是触摸屏拖动它)。 – WOUNDEDStevenJones

回答

1

我相信最简单的方法来改变你的代码实际上是使用USE_ALL_HEIGHT标志。

VerticalFieldManager bgManager = 
    new VerticalFieldManager(Manager.NO_VERTICAL_SCROLL | 
          Manager.NO_VERTICAL_SCROLLBAR | 
          Manager.USE_ALL_WIDTH | 
          Manager.USE_ALL_HEIGHT) { 

这将填充您的屏幕背景图像。

您不显示此代码,但我猜问题不是bgManager实际上允许滚动,而是它允许垂直滚动的Screen。因此,请确保您的代码禁用滚动。类似这样的:

public class BgCropScreen extends MainScreen { 

    public BgCropScreen() { 
     super(MainScreen.NO_VERTICAL_SCROLL); // <<<<<< THIS IS THE CRITICAL LINE !!!!!! 

     VerticalFieldManager bgManager = new VerticalFieldManager(Manager.NO_VERTICAL_SCROLL | Manager.NO_VERTICAL_SCROLLBAR | Manager.USE_ALL_WIDTH | Manager.USE_ALL_HEIGHT) { 
     // to draw the background image. 
     public void paint(Graphics graphics) { 
      graphics.drawBitmap(0, 0, Display.getWidth(), Display.getHeight(), backgroundBitmap, 0, 0); 
      super.paint(graphics); 
     }     
     }; 
     this.add(bgManager); 

Here is the documentation for doing this。它指出,在较新版本的操作系统中,使用BackgroundFactory方法创建背景,使用位图,渐变,颜色等可能更容易。不过,只是另一种选择。

+0

'super(MainScreen.NO_VERTICAL_SCROLL)'正是它!谢谢! – WOUNDEDStevenJones