如何在Codenameone中实现浮动动作按钮?

问题描述:

android中的浮动动作按钮是不错的选择。我想在我的代号应用程序中使用它。我已经通过使用LayeredLayout进行了尝试,它具有两个布局。我无法完美实现。该按钮与滚动一起一直移动。如何将按钮固定在屏幕的右下角,而又不影响背景图层的滚动时间。

Floating Action button in android is good option. I want this in my codenameone application. I have tried it by using LayeredLayout, by having two layouts. I'm unable to achieve it perfectly. The button is keep moving along with the scroll. how to fix the button to the right bottom of the screen without affecting when the background layer is scrolling.

这是我尝试过的方法。

Form myForm = new Form();
myForm.setLayout(new LayeredLayout());
myForm.setTitle("Floating Action Button");

SpanLabel lbl = new SpanLabel("some long text");

Container conBottom = new Container();
conBottom.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
conBottom.addComponent(lbl);

FlowLayout flow = new FlowLayout(Component.RIGHT);
flow.setValign(Component.BOTTOM);
Container conUpper = new Container(flow);
conUpper.addComponent(new Button("+"));
conUpper.setScrollable(false);

myForm.addComponent(conBottom);
myForm.addComponent(conUpper);

myForm.show();

这里的链接类似于我想要实现的链接。
https://github.com/Clans/FloatingActionButton
请帮忙!
谢谢!

Here is the link similar to what i want to achieve. https://github.com/Clans/FloatingActionButton Please Help! Thanks!

表单的内容窗格正在执行滚动,您需要底部的容器来处理滚动。
尝试以下操作:

The Form's content pane is performing the scrolling, you need your bottom container to handle the scrolling instead. Try this:

    Form myForm = new Form();
    myForm.setLayout(new LayeredLayout());
    myForm.setTitle("Floating Action Button");

    SpanLabel lbl = new SpanLabel("some long text ");

    Container conBottom = new Container();
    conBottom.setScrollableY(true);
    conBottom.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
    conBottom.addComponent(lbl);

    FlowLayout flow = new FlowLayout(Component.RIGHT);
    flow.setValign(Component.BOTTOM);
    Container conUpper = new Container(flow);
    conUpper.addComponent(new Button("+"));
    conUpper.setScrollable(false);

    myForm.addComponent(conBottom);
    myForm.addComponent(conUpper);
    myForm.setScrollable(false);
    myForm.show();