0

画面の下部に画像を追加する方法 横方向。これらの画像が画面の水平方向の中央にある場合は、これらの画像を右から左にスライドさせ、開始点にします。これには何を使用すればよいですか。

そのスクロール フィールド Horizo​​ntal field manager のリンクは次のとおりです。 http://appworld.blackberry.com/webstore/content/screenshots/56307/?lang=en このリンクをクリックすると、そのリンクの下部にその画像の画像が表示され、複数の画像を含む水平ファイル マネージャーが表示され、他の画像から見上げたフォーカス画像。

4

1 に答える 1

1

画面の下部に水平方向に画像を追加するには、画面の下部に表示するカスタムが必要ですVerticalFieldManagersublayoutマネージャーのこのオーバーライド メソッドを実現できます。
この VerticalFieldManager にHorizontalFieldManager、すべての画像を含むものを追加します。

HorizontalFieldManager画像を右から左にスライドさせるために、追加されたフィールドが左から右にスクロールするカスタムを作成しました。

public class CustomHorizontalField extends HorizontalFieldManager{

public boolean enableMoving = false;
private int focusOnIndex = 0;   

public void focusChangeNotify(int arg0) {

    super.focusChangeNotify(arg0);

    if(enableMoving)
    {
        int newFocusIndex = getFieldWithFocusIndex();
        if(newFocusIndex != focusOnIndex)
        {
            if( (newFocusIndex - focusOnIndex )> 0 )
            {
                startRotation(0, getFieldCount()-1);        
            }else
            {
                startRotation(getFieldCount()-1, 0);
            }
        }

    }else
    {
        focusOnIndex = getFieldWithFocusIndex();
    }

}
public int getPreferredWidth() {
    return Display.getWidth();
}
public int getPreferredHeight() {
    return super.getPreferredHeight();
}
protected void sublayout(int maxWidth, int maxHeight) {
    super.sublayout(Display.getWidth(), getPreferredHeight());
    setExtent(Display.getWidth(), getPreferredHeight());
}

private void startRotation(int from,int to)
{
    Field field = getField(from);
    delete(field);
    insert(field, to);
}   
}  

これに画像をCustomHorizontalField追加し、このマネージャーをVerticalFieldManager画面の下部に表示されるカスタムに追加します。

編集済み
ビットマップ画像を含むカスタムボタンを作成するコードは次のとおりです。
ビットマップフィールドのように見えるボタンに画像を設定できsetChangeListenerます。また、ボタンに設定して、オーバーライドメソッドで画像をクリックしたときに何をするかのコードを追加できますfieldChanged(Field field, int context)

public class CustomBitmapButtomField extends ButtonField{

   private  Bitmap activeBtn = null;
   private  Bitmap normalBtn = null;
   private  Bitmap focusBtn = null;

   private int btnHeight = 0;
   private int btnWidth = 0;


   public CustomBitmapButtomField(Bitmap normal,Bitmap focus,Bitmap active) {
   activeBtn = active;
   normalBtn = normal ;
   focusBtn = focus;
   btnWidth = normalBtn.getWidth();
   btnHeight = normalBtn.getWidth();
   setMargin(0, 0, 0, 0);
   setPadding(0,0,0,0);
   setBorder(BorderFactory.createSimpleBorder(new XYEdges(0, 0, 0, 0)));
   setBorder(VISUAL_STATE_ACTIVE, BorderFactory.createSimpleBorder(new XYEdges(0, 0, 0, 0)));
   setBackground(BackgroundFactory.createSolidBackground(Color.WHITE));   
   }

   protected void paint(Graphics graphics) {
     Bitmap bitmap = null;
     switch (getVisualState()) {
    case VISUAL_STATE_NORMAL:
        bitmap = normalBtn;
        break;
    case VISUAL_STATE_FOCUS:
        bitmap = focusBtn;
        break;
    case VISUAL_STATE_ACTIVE:
        bitmap = activeBtn;
        break;
    default:
        bitmap = normalBtn;
        break;
    }
    graphics.drawBitmap(0, 0, bitmap.getWidth(), bitmap.getHeight(), bitmap, 0, 0);
}

   public int getPreferredWidth() {
    return btnWidth;
}
   public int getPreferredHeight() {
    return btnHeight;
}
   protected void layout(int width, int height) {
    setExtent(btnHeight,btnHeight);
}
 }
于 2012-04-13T09:42:37.260 に答える