2014-04-25 28 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