我想在屏幕底部设置状态栏,它应该显示一个按钮左侧和一个右侧。你可以在下面看到我的屏幕。 我的代码是这样的..
private void BottomLayout()
{
Bitmap topBg = Bitmap.getBitmapResource(ImageName.topbar);
final Bitmap topBg1 = cmn_fun.resizeBitmap(topBg, SCREEN_WIDTH, topBg.getHeight());
HorizontalFieldManager hfmbottom = new HorizontalFieldManager(Field.USE_ALL_WIDTH)
{
protected void paintBackground(Graphics graphics)
{
graphics.drawBitmap(0,0,SCREEN_WIDTH,topBg1.getHeight(), topBg1,0,0 );
super.paint(graphics);
}
protected void sublayout(int maxWidth, int maxHeight) {
// TODO Auto-generated method stub
super.sublayout(topBg1.getWidth(), topBg1.getHeight());
setExtent(topBg1.getWidth(), topBg1.getHeight());
}
};
Bitmap imgprv=Bitmap.getBitmapResource(ImageName.btn_prev);
Bitmap imgprv_sel=Bitmap.getBitmapResource(ImageName.btn_prev_sel);
btn_prev=new CustomButtonField(0, "", imgprv_sel, imgprv, Field.FIELD_LEFT);
hfmbottom.add(btn_prev);
Bitmap imgnext=Bitmap.getBitmapResource(ImageName.btn_next);
Bitmap imgnext_sel=Bitmap.getBitmapResource(ImageName.btn_next_sel);
btn_next=new CustomButtonField(0, "", imgnext_sel, imgnext, Field.FIELD_RIGHT);
hfmbottom.add(btn_next);
setStatus(hfmbottom);
}
提前致谢。
答案 0 :(得分:3)
我只发布状态栏面板。
实际上在HorizontalFieldManager中它确实会产生问题。
因此,通过以下方式找到它并且它正在工作。它确实添加了额外的代码,但它可以正常工作
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.DrawStyle;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.container.GridFieldManager;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
class SampleBottomPanelScreen extends MainScreen {
private HorizontalFieldManager title_bar;
private VerticalFieldManager btn1_manager;
private ButtonField btn1;
private VerticalFieldManager btn2_manager;
private ButtonField btn2;
Bitmap bg_image;
public SampleBottomPanelScreen() {
//bg_image = Bitmap.getBitmapResource("backgroundImage.png");
btn1_manager = new VerticalFieldManager(VerticalFieldManager.FIELD_LEFT) {
protected void sublayout(int maxWidth, int maxHeight)
{
int displayWidth = Display.getWidth() / 2;
int displayHeight = Display.getHeight();
super.sublayout( displayWidth, displayHeight);
setExtent( displayWidth, displayHeight);
}
};
btn2_manager = new VerticalFieldManager(VerticalFieldManager.FIELD_RIGHT | VerticalFieldManager.USE_ALL_WIDTH) {
protected void sublayout(int maxWidth, int maxHeight)
{
int displayWidth = Display.getWidth() / 2;
int displayHeight = Display.getHeight();
super.sublayout( displayWidth, displayHeight);
setExtent( displayWidth, displayHeight);
}
};
title_bar = new HorizontalFieldManager(Manager.USE_ALL_WIDTH){
public void paint(Graphics graphics) {
graphics.setBackgroundColor(0x2bb1ff);
graphics.clear();
super.paint(graphics);
}
protected void sublayout(int maxWidth, int maxHeight)
{
int displayWidth = Display.getWidth();
int displayHeight = Display.getHeight() / 8;
super.sublayout( displayWidth, displayHeight);
setExtent( displayWidth, displayHeight);
}
};
btn1 = new ButtonField("Submit", ButtonField.LEFT | ButtonField.FIELD_LEFT);
btn2 = new ButtonField("Cancel", ButtonField.RIGHT| ButtonField.FIELD_RIGHT);
btn1_manager.add(btn1);
btn2_manager.add(btn2);
title_bar.add(btn1_manager);
title_bar.add(btn2_manager);
this.add(title_bar);
}
}
答案 1 :(得分:1)
尝试布局管理器类
package com.doapps.blackberry.layouts;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Manager;
public class LayoutManager extends Manager
{
int n;
public LayoutManager(int n)
{
super(Manager.NO_VERTICAL_SCROLL);
this.n =n;
}
protected void sublayout(int width, int height)
{
if(n==2)
{
Field first = getField(0);
Field second = getField(1);
layoutChild(first, this.getPreferredWidth(), this.getPreferredHeight());
layoutChild(second, this.getPreferredWidth(), this.getPreferredHeight());
setPositionChild(first,0, getPreferredHeight() -first.getHeight());
setPositionChild(second,getPreferredWidth()-second.getWidth(), getPreferredHeight() -first.getHeight());
setExtent(width, height);
}
if(n==1)
{
Field second= getField(0);
layoutChild(second, this.getPreferredWidth(), this.getPreferredHeight());
setPositionChild(second,getPreferredWidth()-second.getWidth(), getPreferredHeight() -second.getHeight());
setExtent(width, height);
}
}
public int getPreferredHeight() {
return 45;
}
public int getPreferredWidth() {
return Display.getWidth();
}
}
答案 2 :(得分:1)
我认为你需要使用GridFieldManager。根据需要重新排列以下代码片段并使用填充...
private HorizontalFieldManager createRightTab () {
HorizontalFieldManager hMgr = new HorizontalFieldManager(Field.FIELD_RIGHT);
ImageButtonField button = new ImageButtonField ( Bitmap.getBitmapResource(res.button_1), button_w, button_h);
button.setFocusListener(this);
hMgr.add(button);
return hMgr;
}
private HorizontalFieldManager createLeftTab () {
HorizontalFieldManager hMgr = new HorizontalFieldManager(Field.FIELD_LEFT);
ImageButtonField button = new ImageButtonField ( Bitmap.getBitmapResource(res.button_2), button_w, button_h);
button.setFocusListener(this);
hMgr.add(button);
return hMgr;
}
public void GridControlScreen() {
int w = net.rim.device.api.system.Display.getWidth();
gridMgr = new GridFieldManager(1, 3, 0);
gridMgr.setColumnProperty(0, GridFieldManager.FIXED_SIZE, (button_w));
gridMgr.setColumnProperty(1, GridFieldManager.FIXED_SIZE, (w-(2*button_w)));
gridMgr.setColumnProperty(2, GridFieldManager.FIXED_SIZE, (button_w));
HorizontalFieldManager hMgr_a = createLeftTab();
HorizontalFieldManager hMgr_center = new HorizontalFieldManager();
HorizontalFieldManager hMgr_b = createRightTab();
gridMgr.add(hMgr_a);
gridMgr.add(hMgr_center);
gridMgr.add(hMgr_b);
add(gridMgr);
}
希望这可以提供帮助。
答案 3 :(得分:0)
试试这个
private void BottomLayout()
{
Bitmap topBg = Bitmap.getBitmapResource(ImageName.topbar);
final Bitmap topBg1 = cmn_fun.resizeBitmap(topBg, SCREEN_WIDTH, topBg.getHeight());
HorizontalFieldManager hfmbottom = new HorizontalFieldManager(Field.USE_ALL_WIDTH)
{
protected void paintBackground(Graphics graphics)
{
graphics.drawBitmap(0,0,SCREEN_WIDTH,topBg1.getHeight(), topBg1,0,0 );
super.paint(graphics);
}
protected void sublayout(int maxWidth, int maxHeight) {
// TODO Auto-generated method stub
super.sublayout(topBg1.getWidth(), topBg1.getHeight());
setExtent(topBg1.getWidth(), topBg1.getHeight());
}
};
Bitmap imgprv=Bitmap.getBitmapResource(ImageName.btn_prev);
Bitmap imgprv_sel=Bitmap.getBitmapResource(ImageName.btn_prev_sel);
btn_prev=new CustomButtonField(0, "", imgprv_sel, imgprv, Field.FIELD_LEFT);
hfmbottom.add(btn_prev);
Bitmap imgnext=Bitmap.getBitmapResource(ImageName.btn_next);
Bitmap imgnext_sel=Bitmap.getBitmapResource(ImageName.btn_next_sel);
btn_next=new CustomButtonField(0, "", imgnext_sel, imgnext, Field.FIELD_RIGHT);
btn_next.setPadding(0, 0, 0, Display.getWidth()-btn_prev.getWidth()-btn_next.getWidth());
hfmbottom.add(btn_next);
setStatus(hfmbottom);
}
答案 4 :(得分:0)
这是我们可以设置Field Left和right的另一种方式。 http://keraisureshvblackberry.blogspot.in/2012/02/there-are-very-common-there-there-are.html