【问题标题】:image and spanlabel render default output in List [CodenameOne]image 和 spanlabel 在 List [CodenameOne] 中呈现默认输出
【发布时间】:2016-02-28 07:07:57
【问题描述】:

我拿了一个空白容器并添加了 ImageViewer 和 Spanlabel。列表中的渲染也是如此,但它显示了默认输出(我将其用于测试)。我尝试两种方式动态和手动仍然输出相同。即使我尝试使用 Multi-List,但它没有使用渲染器。

这是我的代码:

    ArrayList<Map<String, Object>> a = new ArrayList<Map<String, Object>>();
    HashMap<String, Object> m = new HashMap<String, Object>();
    Image image=fetchResourceFile().getImage("puzzle_icon.png");
    m.put("gSR_image", image);
    m.put("gSR_label", "Puzzle");
    a.add(m);
    cmp.setModel(new com.codename1.ui.list.DefaultListModel(a));

看到这个输出

我的渲染器屏幕

输出必须是我的图像和它下面写的拼图。

【问题讨论】:

    标签: list codenameone renderer


    【解决方案1】:

    spanlabel 有问题,所以用 textarea 和 unchecked editable 替换 spanlabel,其工作原理与上面类似。

    ArrayList<Map<String, Object>> a = new ArrayList<Map<String, Object>>();
    HashMap<String, Object> m = new HashMap<String, Object>();
    Image image=fetchResourceFile().getImage("puzzle_icon.png");
    m.put("gSR_image", image);
    **m.put("gSR_textarea", "its working");**
    a.add(m);
    cmp.setModel(new com.codename1.ui.list.DefaultListModel(a));
    

    【讨论】:

    • 此处突出显示的另一种选择:codenameone.com/manual/… 是将gSR_image 重命名为gSR_imageFixed,这将阻止渲染器尝试从数据中获取它。
    • 忘记补充说 SpanLabel/Button 在渲染器中不能很好地工作。您应该使用 TextArea 并相应地设置它的样式。另请注意,上述组件将不会像在常规容器中那样动态换行。
    • @ShaiAlmog 您的解决方案适用于文本,但对于图像同样不起作用。我尝试在末尾添加 Fixed 单词,但这项工作的标签不是 ImageViewer,同样是强制 Label 选择在渲染器中设置的图像。最后的解决方案是将ImageViewer 替换为Label,并且名称末尾必须没有Fixed 字样。 Image image=fetchResourceFile().getImage("puzzle_icon.png"); m.put("gSR_image", image); 现在完美运行。
    • 您是否将ImageViewer 嵌入到渲染器中???这不是一个好主意。不要那样做。如果您需要缩放,请使用ScaleImageLabel
    猜你喜欢
    • 2020-07-09
    • 1970-01-01
    • 2021-10-14
    • 2021-02-06
    • 1970-01-01
    • 1970-01-01
    • 2013-01-12
    • 2012-05-27
    • 2012-09-29
    相关资源
    最近更新 更多