2014-04-25 27 views
0

我在針對圖標顯示通知計數時遇到問題。它應該顯示在右上角。在CodaNameone中顯示通知計數

首先創建帶有填充和邊距爲零的按鈕並將圖像設置爲按鈕。

FlowLayout buttonLayout = new FlowLayout(); 
buttonLayout.setAlign(Component.CENTER); 
buttonLayout.setValign(Component.TOP); 
Container buttonContainer = new Container(buttonLayout); 
buttonContainer.setUIID("IconContainer"); 
Button button = new Button(buttonImage); 
button.setUIID("ButtonLabelNew"); 
buttonContainer.addComponent(button); 

所創建的通知計數容器,把它在按鈕

FlowLayout countLayout = new FlowLayout(); 
countLayout.setAlign(Component.RIGHT); 
countLayout.setValign(Component.TOP); 
Container countContainer = new Container(countLayout); 
Label countLabel = new Label(displayCount); 
countLabel.setUIID("backgroundLabel"); 
countContainer.addComponent(countLabel); 

/*Adding Button and Notification Count to ItemContainer*/ 
Container itemContainer = new Container(new LayeredLayout()); 
itemContainer.addComponent(buttonContainer); 
itemContainer.addComponent(countContainer); 

立即添加的按鈕

BoxLayout iconLayout = new BoxLayout(BoxLayout.Y_AXIS); 
Container iconContainer = new Container(iconLayout); 
Label iconText= new Label(buttonText); 
iconText.setUIID("Label"); 
iconContainer.addComponent(0,itemContainer); 
iconContainer.addComponent(1,iconText); 

最後創建的格下面的文本和添加的圖標的容器到電網

GridLayout gridLayout = new GridLayout(numRows, MAX_ITEMS_PER_ROW); 
Container gridContainer = new Container(gridLayout); 
gridContainer.setUIID("LogoContainer"); 
for (int indx = 0; indx < itemContainers.length; indx++) 
{ 
    gridContainer.addComponent(itemContainers[indx]); 
} 
approvalsWorklist.addComponent(BorderLayout.CENTER,gridContainer); 
+1

什麼不在這裏工作?這似乎是正確的大部分。你能否提供你所得到的截圖,並解釋爲什麼它與你期望的最終結果不同? –

+0

Shai我在這裏發佈圖片(https://www.dropbox.com/s/6wep74gq4oxoe60/grid.png) – user3304328

+0

問題是通知計數並不出現在確切的右上角。這裏有一個餘地。 – user3304328

回答

0

圖像位於右側,但組件大於圖標,因此您會看到圖像位於組件大小的位置。

有兩種方法可以解決這個問題。

  1. 設置上countContainer填充或餘量,從而計數將隔開並放置在正確的位置。這有一個缺點,就是不得不根據統一的圖標大小進行調整,這可能並非如此,但它是一種相對簡單的方法。

  2. 我假設組件放置在GridLayout這意味着它們都具有完全相同的大小。您會將網格佈局中的每個元素都包含在FlowLayout或絕對中心BorderLayout中,他們將在內部佔用他們的首選大小,然後將徽章精確定位在圖標邊緣內。

+0

我確實嘗試過這些方法,但沒有奏效。最後我改變了網格的使用方式。我沒有在網格中使用下面的圖標和文本,而是使用了一行圖標和下一行相關文本。 – user3304328