2009-07-07 9 views
1
나는 HFM

블랙 베리 - 필드 - 수평 방향의 배치

final HorizontalFieldManager _navigation = new HorizontalFieldManager(HorizontalFieldManager.NO_VERTICAL_SCROLL | HorizontalFieldManager.FIELD_VCENTER | Field.USE_ALL_WIDTH) 
{  
protected void paint(Graphics graphics) 
{ 
    graphics.setGlobalAlpha(100); 

    int[] xInds = new int[]{0, getExtent().width, getExtent().width, 0}; 
    int[] yInds = new int[]{0, 0, getExtent().height, getExtent().height}; 
    final int[] cols = new int[]{Color.WHITE, Color.WHITE, color_computacenter_light_blue, color_computacenter_light_blue}; 

    graphics.drawShadedFilledPath(xInds, yInds, null, cols, null); 
    super.paint(graphics); 
} 
protected void sublayout(int maxWidth, int maxHeight) 
    { 
     super.sublayout(maxWidth, maxHeight); 
     setExtent(maxWidth, navigation_vertical_manager_height); 
    } 
}; 

alt text

정의 '수평 관리자의 중심에 사용자 정의 버튼 필드 (스크린 샷의 스타를) 정렬 할

맞춤 필드 (부분)

public class NavigationButton extends Field 
{ 
    private String label; 
    Bitmap img; 
    int horizontalPadding = 4; 
    int verticalPadding = 10; 
    static int height; 
    static int weight; 
    ToolTip _tooltip; 

    public NavigationButton(String name, Bitmap img) 
    { 
     label = name; 
     this.img = img; 
     this.height = img.getHeight() + 4; 
     this.weight = img.getWidth() + 2; 
    } 

    public NavigationButton(String name, Bitmap img, long style) 
    { 
     super(style); 
     label = name; 
     this.img = img; 
     this.height = img.getHeight() + 4; 
     this.weight = img.getWidth() + 2; 
    } 

    protected void layout(int maxWidth, int maxHeight) 
    { 
     setExtent(maxWidth, maxHeight); 
     // setExtent(Math.min(weight, maxWidth), Math.min(height, maxHeight)); 
    } 

    protected void paint(Graphics graphics) 
    { 
     // Draw background 
     graphics.setGlobalAlpha(255); 
     if(isFocus()) 
     { 
      graphics.setColor(0x005AA1); 
      graphics.drawRoundRect(0 ,0 , weight + 1, height + 1, 2, 2); 
     } 
     if (img != null) 
     { 
      graphics.drawBitmap(0, 0 , img.getWidth(), img.getHeight(), img, 0, 0); 
     } 
    } 

[...]

모든 아이디어, 내가 뭘 잘못하고있어?!

감사합니다.

+0

당신은 당신을 달성하기 위해 노력하고 무엇을하는지 동작에 대한 자세한 명시 할 수있다 ' 실제로보고 있니? 스크린 샷이 좋습니다! –

+0

안녕하세요. 안소니, 스크린 샷을 추가했습니다. –

답변

4

나는 밖으로이 코드를 테스트하지 않은,하지만 난 당신의 문제는 자신의 분야의 배치 방법에 의심 :

protected void layout(int maxWidth, int maxHeight) 
    { 
     setExtent(maxWidth, maxHeight); 
     // setExtent(Math.min(weight, maxWidth), Math.min(height, maxHeight)); 
    } 

해당 라인을 주석 이유가 있습니까? 내 생각 엔 사용자 정의 필드가 전체 너비를 차지하고 있으며, 페인트 메소드에서 가장 왼쪽에 비트 맵을 그려서 필드가 왼쪽으로 정렬 된 것처럼 보이게 만드는 것입니다. 해당 줄의 주석 처리를 제거하고 Field.FIELD_HCENTER 필드 스타일 비트를 추가하면 필드를 구성 할 때 작동합니다.

는 여전히 전체 폭을 차지합니다이

graphics.drawBitmap((this.getWidth()-img.getWidth())/2, 0 , img.getWidth(), img.getHeight(), img, 0, 0); 

필드처럼 뭔가에 페인트 방법의 라인을 변경하여, 그대로 또는, 레이아웃을 유지할 수 있습니다, 그냥 비트 맵을 중심으로 그리기 그러나 이미지는 중앙에 배치됩니다. 이로 인해 터치 스크린 장치 (예 : 폭풍)에서 예기치 않은 동작이 발생할 수 있습니다.

1

사실 매우 간단합니다. HorizontalFieldManger와 DrawStyle.Center를 사용해야합니다. 여기 가 (당신이 아직 해결되지 않은 경우) 코드입니다 : 친절

HorizontalFieldManager hfm = new HorizontalFieldManager(HorizontalFieldManager.FIELD_HCENTER); 
    ButtonField button = new ButtonField("Button",DrawStyle.HCENTER); 
    hfm.add(button); 

, 흐르 보예