2011-05-14 3 views
2

Field를 확장하는 사용자 정의 항목이 포함 된 절대 레이아웃으로 메뉴를 만들려고합니다. 이 항목은 예를 들어 HorizontalFieldManager에 잘 표시되지만 AbsoluteFieldManager에서는 빈 화면 만 표시합니다.blackberry : AbsoluteFieldManager 사용자 정의 필드 표시 안 함

이 내 코드는 지금까지 있습니다 :

/******************** 
* CustomField.java * 
********************/ 

import net.rim.device.api.system.Bitmap; 
import net.rim.device.api.ui.Field; 
import net.rim.device.api.ui.Font; 
import net.rim.device.api.ui.Graphics; 
import net.rim.device.api.ui.Keypad; 

public class CustomField extends Field { 
    Bitmap img; 
    String s1, s2; 
    Font font; 
    int textColorUnfocused, textColorFocused, bgColorUnfocused, bgColorFocused; 

    public CustomField(long style) { 
     super(style); 
    } 

    public CustomField(Bitmap img, String s1, String s2) {// , long style) { 
     // super(style); 
     this.img = img; 
     this.s1 = s1; 
     this.s2 = s2; 
     this.font = Font.getDefault(); 
     textColorUnfocused = 0x000000; 
     textColorFocused = 0xffffff; 
     bgColorUnfocused = 0xffffff; 
     bgColorFocused = 0x3956F7; 
    } 

    protected void layout(int maxWidth, int maxHeight) { 
     Font font = getFont(); 
     int width = img.getWidth() + 10; 
     int height = img.getHeight() + (font.getHeight() * 3); 
     setExtent(Math.min(width, maxWidth), Math.min(height, maxHeight)); 

    } 

    protected void onFocus(int direction) { 

     super.onFocus(direction); 
     invalidate(); 
    } 

    protected void onUnfocus() { 
     super.onUnfocus(); 
     invalidate(); 
    } 

    public boolean isFocusable() { 
     return true; 
    } 

    protected void paint(Graphics g) { 

     // Draw background 
     g.setColor(isFocus() ? bgColorFocused : bgColorUnfocused); 
     g.fillRect(0, 0, getWidth(), getHeight()); 
     // draw image 
     g.drawBitmap(5, 5, img.getWidth(), img.getHeight(), img, 0, 0); 

     g.setColor(isFocus() ? textColorFocused : textColorUnfocused); 
     // draw text 
     g.drawText(s1, ((img.getWidth() + 10)/2) - (font.getAdvance(s1)/2), 
       img.getHeight() + font.getHeight()); 
     g.drawText(s2, ((img.getWidth() + 10)/2) - (font.getAdvance(s2)/2), 
       img.getHeight() + (2 * font.getHeight())); 

    } 

    protected boolean keyChar(char character, int status, int time) { 
     if (character == Keypad.KEY_ENTER) { 
      fieldChangeNotify(0); 
      return true; 
     } 
     return super.keyChar(character, status, time); 
    } 

    public int getY() { 

     return img.getHeight() + (font.getHeight() * 3); 
    } 

    public int getX() { 
     return img.getWidth(); 
    } 

}  

/************** 
* MyApp.java * 
**************/ 
import net.rim.device.api.ui.UiApplication; 


public class MyApp extends UiApplication{ 
    public static void main(String args[]){ 

     MyApp theApp = new MyApp();  
     theApp.enterEventDispatcher(); 
    } 
    public MyApp() 
    {   
     // Push a screen onto the UI stack for rendering. 
     pushScreen(new MyScreen()); 
    } 
} 




/***************** 
* MyScreen.java * 
*****************/ 
import net.rim.device.api.system.Bitmap; 
import net.rim.device.api.ui.Manager; 
import net.rim.device.api.ui.container.AbsoluteFieldManager; 
import net.rim.device.api.ui.container.HorizontalFieldManager; 
import net.rim.device.api.ui.container.MainScreen; 

public class MyScreen extends MainScreen { 
    public MyScreen() { 
     AbsoluteFieldManager manager = new AbsoluteFieldManager(); 
     Bitmap img = Bitmap.getBitmapResource("1.png"); 
     CustomField cf1 = new CustomField(img, "an", "Item"); 
     CustomField cf2 = new CustomField(img, "another", "Item"); 
     manager.add(cf1, 10, 10); 
     manager.add(cf2, 150, 150); 
     //HorizontalFieldManager hfm = new HorizontalFieldManager(
      // Manager.HORIZONTAL_SCROLL); 
     //hfm.add(cf1); hfm.add(cf2); 
     //add(hfm); 
     add(manager); 
    } 

} 

그리고 이미지 (1.png를) http://www7.pic-upload.de/14.05.11/rhr4jcfuy9f8.png

내 사용자 정의 필드를 표시하는 절대 매니저를 얻을 수있는 방법

?

답변

1

아마도 내 생각에 AbsoluteFieldManager0, 0을 사용자 지정 필드의 layout 메서드에 전달합니다. 그래서 당신의 논리는 setExtent(0, 0)입니다.

+0

네가 맞아, 고마워! – Cypherpunks