1

ButtonFieldsで構成されるメニューを設定するための非常に基本的なカスタムレイアウトを作成しました。

それらを垂直に配置するには、画面を6つに分割してから、コードに示されているように2、3、4、5の分割に配置します。

したがって、エミュレーターのトーチの場合、高さが480の場合、ボタンは160、240、320、および400に表示されます。

しかし、私がそれらをチェックすると、それらはすべてこれより24ピクセル下にあり、これが私が見逃した典型的な慣習でない限り、明白な理由はないようです!

package Test;

import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.container.VerticalFieldManager;

class MenuLayoutManager extends VerticalFieldManager{

public MenuLayoutManager()
{
    super();
}

public int getPreferredWidth()
{
    int preferredWidth = Display.getWidth();
    return preferredWidth;
}

protected void sublayout(int inMaxWidth, int inMaxHeight)
{
int xCentre = Display.getWidth()/2;
int yGap = Display.getHeight() / 6;
int xPos = 0;
int yPos = yGap * 2;
int fieldNo = this.getFieldCount();

for(int index = 0; index<fieldNo; index++)
{
Field aField = this.getField(index);
this.layoutChild(aField, inMaxWidth, inMaxHeight);
xPos = xCentre - (aField.getWidth() / 2);
this.setPositionChild(aField, xPos, yPos);
yPos += yGap;
}
this.setExtent(inMaxWidth, inMaxHeight);


}
}

------エントリポイントとボタンの作成----

package Test;


import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.container.MainScreen;

class MyScreen extends MainScreen
{
public MyScreen(){
super(MainScreen.NO_VERTICAL_SCROLL|MainScreen.NO_VERTICAL_SCROLLBAR);
this.initialize();
}

private void initialize()
{        
    // Set the displayed title of the screen


    this.setTitle(String.valueOf("Ben's Menu"));

    MenuLayoutManager mlm = new MenuLayoutManager();
    ButtonField Button1 = new ButtonField("New Game");
    ButtonField Button2 = new ButtonField("High Scores");
    ButtonField Button3 = new ButtonField("Instructions");
    ButtonField Button4 = new ButtonField("Exit");
    mlm.add(Button1);
    mlm.add(Button2);
    mlm.add(Button3);
    mlm.add(Button4);
    this.add(mlm); 


}



}
4

1 に答える 1

2

MainScreenでは、画面のコンテンツに割り当てられた表示の高さ全体を取得することはできません。(少なくとも、IIRCには、タイトルと区切り文字があります。)代わりにフルスクリーンを使用してみて、何が起こるかを確認してください。

于 2011-09-11T17:48:39.390 に答える