2017-01-11 58 views
1

我试图将com.codename1.components.FloatingActionButtoncom.codename1.ui.TextArea组合使用。TextArea上的FloatingActionButton按预期工作

现在我有两个问题:

  1. 显然,VALIGN不兑现 - 它是一个错误吗?
  2. FloatingActionButton的actionListener未被调用。我的用法有什么问题吗?或者它是一个错误?

这里是展示它的代码:

public class FormFabOnText extends Form { 
    public FormFabOnText() { 
     setTitle("FormFabOnText"); 
     setLayout(new BorderLayout()); 
     Container contentPane = getContentPane(); 
     contentPane.add(BorderLayout.NORTH, new SpanLabel(
       "This form contains a TextArea and a FloatingActionButton combined by bindFabToContainer. " 
       + "It demonstrates that the FloatingActionButton is not working in this constellation.")); 
     TextArea textArea = new TextArea(); 
     float iconDefaultSize = FloatingActionButton.getIconDefaultSize(); 
     try { 
      FloatingActionButton.setIconDefaultSize(2.0f); 
      FloatingActionButton floatingActionButton = FloatingActionButton.createFAB(FontImage.MATERIAL_CLEAR); 
      Container containerFab = floatingActionButton.bindFabToContainer(textArea, Component.RIGHT, Component.CENTER); 
      floatingActionButton.addActionListener((e) -> textArea.setText("")); 
      contentPane.add(BorderLayout.CENTER, containerFab); 
     } finally { 
      FloatingActionButton.setIconDefaultSize(iconDefaultSize); 
     } 
    } 
} 
+0

看起来像'com.codename1.ui.Container.getComponentAt(int,int)'方法需要对LayeredLayout进行特殊处理 –

+0

显然'调用FloatingActionButton.pointerPressed'和'FloatingActionButton.pointerReleased' - 所以出了什么问题? –

+0

当'TextArea'聚焦时'FloatingActionButton'不起作用,那么'com.codename1.ui.Container.getComponentAt(int,int)'根本不会被调用 –

回答

0

文本区域具有高度为0,所以当你VALIGN到按钮正确地放置于顶部的中心。然后将其添加到边界布局中,但是文本区域的首选大小决定了它的维度,因此它保持不变。

我不确定是否有一个很好的解决方法,除了像我们在msuikit demo所做的那样有一点余量。

编辑期间点击问题可能与本地编辑点有关。在文本区域内轻敲会发送到本地图层进行编辑,否则以下元素可能会导致问题。文本输入是一个同龄人,但也是一个非常特殊的情况。

+0

容器由'bindFabToContainer'是contentPane的'BorderLayout.CENTER',因此应该有一个定义的高度。在这两种情况下,我都觉得它可能无法按预期工作,难道你不这么认为吗? –