2012-03-27 4 views
0

두 개의 labelfield가있는 가로 관리자의 오른쪽에 이미지를 표시하려고합니다. 이미지를 추가 할 때 labelfield vainshed의 데이터가 표시되고 오른쪽에만 이미지가 표시됩니다. .I은 다음과 같이 정의 비트 맵 필드를 사용하고 있습니다 :가로 관리자의 오른쪽에 이미지 표시

Public class screen{ 
    HorizontalFieldManager horizontalFieldManager_left1 = new HorizontalFieldManager() { 
    protected boolean keyChar(char key, int status, int time) { 
       Field field = getFieldWithFocus(); 
       Dialog.alert("here 1"); 
       return super.keyChar(key, status, time); 
      } 
     }; 
     final ImageButtonField alarmBitmapField = new ImageButtonField("", 
       Field.FOCUSABLE, "ringtone.png", "ringtone.png", 0x9cbe95); 
     System.out 
       .println("width is ::" + alarmBitmapField.getPreferredWidth()); 
     alarmBitmapField.setMargin(0, 0, 0, Display.getWidth() 
       - alarmBitmapField.getPreferredWidth()); 
     horizontalFieldManager_left1.add(alarmBitmapField); 
     horizontalFieldManager_left1.add(time1); 
     horizontalFieldManager_left1.add(min1); 
     horizontalFieldManager_left1.add(new LabelField(" ")); 
     horizontalFieldManager_left1.add(desc1); 

     vfm.add(horizontalFieldManager_left1); 


} 

사용자 정의 클래스

public class ImageButtonField extends Field { 

     private String _label; 
     private int _labelHeight; 
     private int _labelWidth; 
     private Font _font; 

     private Bitmap _currentPicture; 
     private Bitmap _onPicture; 
     private Bitmap _offPicture; 
     int color; 

     public ImageButtonField(String text, long style, String img, 
       String img_hvr, int color) { 
      super(style); 

      _offPicture = Bitmap.getBitmapResource(img); 
      _onPicture = Bitmap.getBitmapResource(img_hvr); 

      _font = getFont(); 
      _label = text; 
      _labelHeight = _onPicture.getHeight(); 
      _labelWidth = _onPicture.getWidth(); 

      this.color = color; 

      _currentPicture = _offPicture; 
     } 

     /** 
     * @return The text on the button 
     */ 
     String getText() { 
      return _label; 
     } 

     /** 
     * Field implementation. 
     * 
     * @see net.rim.device.api.ui.Field#getPreferredHeight() 
     */ 
     public int getPreferredHeight() { 
      return _labelHeight; 
     } 

     /** 
     * Field implementation. 
     * 
     * @see net.rim.device.api.ui.Field#getPreferredWidth() 
     */ 
     public int getPreferredWidth() { 
      return _labelWidth; 
     } 

     /** 
     * Field implementation. Changes the picture when focus is gained. 
     * 
     * @see net.rim.device.api.ui.Field#onFocus(int) 
     */ 
     protected void onFocus(int direction) { 
      _currentPicture = _onPicture; 
      invalidate(); 
     } 

     /** 
     * Field implementation. Changes picture back when focus is lost. 
     * 
     * @see net.rim.device.api.ui.Field#onUnfocus() 
     */ 
     protected void onUnfocus() { 
      _currentPicture = _offPicture; 
      invalidate(); 
     } 

     /** 
     * Field implementation. 
     * 
     * @see net.rim.device.api.ui.Field#drawFocus(Graphics, boolean) 
     */ 
     protected void drawFocus(Graphics graphics, boolean on) { 
      // Do nothing 
     } 

     /** 
     * Field implementation. 
     * 
     * @see net.rim.device.api.ui.Field#layout(int, int) 
     */ 
     protected void layout(int width, int height) { 
      setExtent(Math.min(width, getPreferredWidth()), 
        Math.min(height, getPreferredHeight())); 
     } 

     /** 
     * Field implementation. 
     * 
     * @see net.rim.device.api.ui.Field#paint(Graphics) 
     */ 
     protected void paint(Graphics graphics) { 
      // First draw the background colour and picture 
      graphics.setColor(this.color); 
      graphics.fillRect(0, 0, getWidth(), getHeight()); 
      graphics.drawBitmap(0, 0, getWidth(), getHeight(), _currentPicture, 0, 
        0); 

      // Then draw the text 
      graphics.setColor(Color.BLACK); 
      graphics.setFont(_font); 
      graphics.drawText(
        _label, 
        4, 
        2, 
        (int) (getStyle() & DrawStyle.ELLIPSIS | DrawStyle.HALIGN_MASK), 
        getWidth() - 6); 
     } 

     /** 
     * Overridden so that the Event Dispatch thread can catch this event instead 
     * of having it be caught here.. 
     * 
     * @see net.rim.device.api.ui.Field#navigationClick(int, int) 
     */ 
     protected boolean navigationClick(int status, int time) { 
      fieldChangeNotify(1); 
      return true; 
     } 

    } 
+0

게시물 서식을 수정 한 다음 우리는 당신 –

+0

@CarlosGavidia이 – user1195292

답변

1
당신은 GridFieldManager를 사용하여 문제를 해결할 수

에 설명 된대로 : Search bar on top of the mainscreen blackberry

전체 설명 here.

+0

그게 전부 의식을 편집 할 수 있지만 내 전체 응용 프로그램은 HFM에 내장되어 있습니다, 그래서 미안 해요 그것 – user1195292

+0

으로 가능하게 할 수있는 방법을 볼 필요가 있지만 HorizontalFieldManager를 사용하여 모든 작업을 수행 할 수는 없다고 생각하십시오. – rosco

+0

레이아웃이나 무언가를 사용하여 atlead해야합니다. – user1195292

관련 문제