画面の全幅と高さの10%を占めるhorizontalfieldmaangerを1つ作成しました。ここで、このマネージャーにそれぞれ3つのフィールドを追加します。1つ目はBitmapField(画面の幅10%)、2つ目はLabelField(画面の幅80%)、3つ目はBitmapField(画面の幅10%)になります。
残っているのは、これらのフィールドのコンテンツをフィールド自体の中央に配置することです。
コードは次のとおりです:-
public final class MyScreen extends MainScreen
{
public MyScreen()
{
final int disWidth = Display.getWidth();
final int disHeight = Display.getHeight();
final int heightHFM = (disHeight*10)/100;
HorizontalFieldManager hfm = new HorizontalFieldManager(){
protected void sublayout(int maxWidth, int maxHeight) {
// TODO Auto-generated method stub
super.sublayout(maxWidth, maxHeight);
this.setExtent(disWidth,heightHFM);
}
};
hfm.setBackground(BackgroundFactory.createSolidBackground(Color.GRAY));
BitmapField bmp_leftArrow = new BitmapField(Bitmap.getBitmapResource("arrow_left.png")){
protected void layout(int width, int height) {
// TODO Auto-generated method stub
super.layout(width, height);
this.setExtent((disWidth*10)/100, height);
}
};
bmp_leftArrow.setBackground(BackgroundFactory.createSolidBackground(Color.BLUE));
LabelField lbl_tit = new LabelField("Current Date"){
protected void layout(int width, int height) {
// TODO Auto-generated method stub
super.layout(width, height);
this.setExtent((disWidth*80)/100, height);
}
};
lbl_tit.setBackground(BackgroundFactory.createSolidBackground(Color.RED));
BitmapField bmp_rightArrow = new BitmapField(Bitmap.getBitmapResource("arrow_left.png")){
protected void layout(int width, int height) {
// TODO Auto-generated method stub
super.layout(width, height);
this.setExtent((disWidth*10)/100, height);
}
};
bmp_rightArrow.setBackground(BackgroundFactory.createSolidBackground(Color.GREEN));
hfm.add(bmp_leftArrow);
hfm.add(lbl_tit);
hfm.add(bmp_rightArrow);
add(hfm);
}
}
Androidで任意のビューの重力を使用する場合、同じ出力を達成する必要があります