【问题标题】:ImageViewer isnot working fine codenameone图像查看器无法正常工作代号一
【发布时间】:2016-08-14 18:38:13
【问题描述】:

我有几个关于图像查看器的问题。

1)ImageViewer autoslides 不工作。当应用程序首次启动时,imageViewer 最初工作。但是一旦打开任何其他表单然后返回到包含 imageViewer 的表单,自动滑动就不起作用了。

img 查看器自动幻灯片的代码

placeholderForTable = (EncodedImage) theme.getImage("placeholderWithAnimate.png");
placeholderForTable = placeholderForTable.scaledEncoded(screenWidth, 30 + (screenWidth * 1 / 3));
BusinessForumImagesConnection bfic = new BusinessForumImagesConnection();
bfic.businessForumImagesConnectionMethod(new ActionListener() {

@Override
public void actionPerformed(ActionEvent evt) {
    DefaultListModel<Image> images;
    if (bfic.response != null) {
        for (Map<String, Object> entrySet : bfic.response) {
            String imgUrl = (String) entrySet.get("imgUrl");
            Image adImage = URLImage.createToStorage(placeholderForTable, imgUrl.substring(0, imgUrl.lastIndexOf(".")), + imgUrl, URLImage.RESIZE_SCALE);
            adsSlideImagesArray.add(adImage);
        }
    }

    ImageViewer imv = new ImageViewer();
    Container adsContainer = BoxLayout.encloseY(imv);

    if (adsSlideImagesArray != null) {
        slideIndex = 0;
        images = new DefaultListModel<>(adsSlideImagesArray);
        imv.setImage(images.getItemAt(0));
        imv.setImageList(images);
        imv.setSwipePlaceholder(Image.createImage(100, 100));
        Runnable r = new Runnable() {
            public void run() {
                if (slideIndex < images.getSize()) {
                    nextImage = (Image) images.getItemAt(slideIndex);
                    if (nextImage != null) {
                        imv.setImage(nextImage);
                    }
                    slideIndex++;
                } else {
                    slideIndex = 0;
                }
            }
        };
        if (uITimer == null) {
            uITimer = new UITimer(r);
        }
        if (uITimer != null) {
            uITimer.schedule(5000, true, f); //5 seconds
        }
    }
});

2) 一些随机图像并不总是显示在图像查看器中。它发生在模拟器和真实设备中。我检查了 UrlImage 是否缓存在存储中。保存了所有文件,但其中一些文件从未显示在图像查看器中。 而不是图像查看器,我在标签中设置图像图标并循环它们。所有的标签都有各自的图标,但是在 imageViewer 中出现了问题。代码同上。

【问题讨论】:

    标签: codenameone


    【解决方案1】:
    1. 确保您的计时器触发并且没有人取消它。

    2. 您看到的是占位符而不是图像吗?像这样的细节是必不可少的。

    图像查看器堆栈中较深的图像不会被预取。请注意,URLImage 不是为图像查看器设计的,并且可能是一个坏主意,因为URLImage 会调整图像大小。我们建议使用下载方法为图像查看器获取全尺寸图像,请参阅此旧帖子:https://www.codenameone.com/blog/image-viewer-from-the-web.html

    【讨论】:

    • System.out.println(nextImage) 在可运行的作品中,所以我认为计时器工作正常,但自动滑动停止。对于第二个问题,是的,我只看到占位符 img 而不是实际图像(Ps 文件已存储在 .cn1 文件夹中)但未显示。
    • URLImage 很特别。同样,不要将它用于图像查看器。我建议使用调试器并验证计时器是否正在为当前屏幕上的视图设置动画。
    • 谢谢...我解决了。对于计时器,我犯了一个小错误,如果它为空,我已经初始化了 uiTimer。所以它是第一次运行,如果我从其他表单恢复到这个表单,它就不起作用。一开始设置 uiTimer = null 即可解决问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-11
    • 1970-01-01
    • 2013-04-17
    • 2015-07-25
    • 2019-01-11
    • 2012-07-04
    相关资源
    最近更新 更多