如何在Codenameone中实现浮动动作按钮? [英] How to achieve Floating Action Button in Codenameone?

查看:46
本文介绍了如何在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();

这篇关于如何在Codenameone中实现浮动动作按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆