Codenameone 回复:ScaleImageLabel工作不正常

Codenameone 回复:ScaleImageLabel工作不正常,codenameone,Codenameone,使用scaledImageButton类来缩放网格单元中的按钮,但不知何故,它工作得不好。当我将scaleImageButton类的背景行为类型保持为缩放图像时,网格之间存在间隙,如果我将其设置为缩放图像,则在上述网格之间创建的间隙将替换为其自身的缩放图像。因此,在单个网格单元中可以看到两个重复图像。代码和屏幕截图如下所示: 我的代码: GridLayout gr = new GridLayout(1, 2); gr.setAutoFit(true); Container

使用scaledImageButton类来缩放网格单元中的按钮,但不知何故,它工作得不好。当我将scaleImageButton类的背景行为类型保持为缩放图像时,网格之间存在间隙,如果我将其设置为缩放图像,则在上述网格之间创建的间隙将替换为其自身的缩放图像。因此,在单个网格单元中可以看到两个重复图像。代码和屏幕截图如下所示:

我的代码:

    GridLayout gr = new GridLayout(1, 2);
    gr.setAutoFit(true);
    Container gridContainer = new Container(gr);
    gridContainer.setUIID("containerGridImgGallery");
    gridContainer.getAllStyles().setPadding(0, 0, 0, 0);
    gridContainer.getAllStyles().setMargin(0, 0, 0, 0);
    gridContainer.getAllStyles().setBorder(Border.createEmpty());
    gridContainer.setScrollableY(true);
    EncodedImage a = URLImage.createToStorage(placeholder, galleryPhotoTitle + offset + imageId + "bibek", galleryPhotoUrl, URLImage.RESIZE_SCALE_TO_FILL);
    ScaleImageButton scaleImageButton = new ScaleImageButton();
    scaleImageButton.setIcon(a);
    gridContainer.addComponent(scaleImageButton)
    f.addComponent(gridContainer);
    f.revalidate();
ScaleImageButton类:

public class ScaleImageButton extends Button {

    /**
     * Default constructor
     */
    public ScaleImageButton() {
        setUIID("Container");
        setShowEvenIfBlank(true);
        setBackgroundType(Style.BACKGROUND_IMAGE_SCALED_FIT);
    }

    /**
     * Create a version with the given image
     *
     * @param i image
     */
    public ScaleImageButton(Image i) {
        setUIID("Container");
        setShowEvenIfBlank(true);
        setBackgroundType(Style.BACKGROUND_IMAGE_SCALED_FIT);
        setIcon(i);
    }

    /**
     * Sets the behavior of the background to one of
     * Style.BACKGROUND_IMAGE_SCALED_FIT,
     * Style.BACKGROUND_IMAGE_SCALED_FILL, Style.BACKGROUND_IMAGE_SCALE
     *
     * @param behavior the background behavior
     */
    public void setBackgroundType(byte behavior) {
        getUnselectedStyle().setBackgroundType(behavior);
        getSelectedStyle().setBackgroundType(behavior);
        getPressedStyle().setBackgroundType(behavior);
    }

    public byte getBackgroundType() {
        return getUnselectedStyle().getBackgroundType();
    }

    @Override
    protected Dimension calcPreferredSize() {
        Image i = getIcon();
        if (i == null) {
            return new Dimension();
        }
        Style s = getStyle();
        return new Dimension(i.getWidth() + s.getPaddingLeft(false) + s.getPaddingRight(false), i.getHeight()
                + s.getPaddingTop() + s.getPaddingBottom());
    }

    public void setIcon(Image i) {
        getUnselectedStyle().setBgImage(i);
        getSelectedStyle().setBgImage(i);
        getPressedStyle().setBgImage(i);
    }

    public Image getIcon() {
        return getUnselectedStyle().getBgImage();
    }


    @Override
    public void setText(String text) {
    }

    @Override
    public Image getIconFromState() {
        return getIcon();
    }

    @Override
    public void setUIID(String id) {
        Image icon = getIcon();
        super.setUIID(id);
        setIcon(icon);
    }
}
背景行为类型到样式。背景\u图像\u缩放\u匹配

背景行为类型到样式。背景\图像\缩放\填充


我们最近修复了一个bug。尝试使用
getUnselectedStyle()
查看它是否能在下次更新之前解决问题。

我们最近修复了一个bug。请尝试使用
getUnselectedStyle()
查看它是否能解决问题,直到下一次更新。

我只在gridContainer ie中使用了getAllStyles来设置填充、边距和边框。我将它们替换为getUnselectedStyle()、getSelectedStyle()和getPressedStyle,但结果相同。背景中有反射图像。您是如何将“缩放图像”的值更改为“填充”的?看起来您在使用fit代码后更改了它,但不知为什么fit代码仍然存在?另外,为UIID使用“容器”可能是个坏主意,默认情况下它是透明的。使用bg透明度设置为255的UIID,以避免在递归中绘制其他背景。我将缩放图像更改为填充ScaleImageButton构造函数。我为构造函数使用了Label,它没有像UIId那样工作。我也尝试过Style.BACKGROUND\u IMAGE\u SCALED、Style.BACKGROUND\u IMAGE\u SCALED\u FIT和Style.BACKGROUND\u IMAGE\u SCALED\u FILL和cleanned storage,但结果是一样的。你是否将bg透明度设置为255?我只在gridContainer中使用了getAllStyles,即设置填充、边距和边框。我将它们替换为getUnselectedStyle()、getSelectedStyle()和getPressedStyle,但结果相同。背景中有反射图像。您是如何将“缩放图像”的值更改为“填充”的?看起来您在使用fit代码后更改了它,但不知为什么fit代码仍然存在?另外,为UIID使用“容器”可能是个坏主意,默认情况下它是透明的。使用bg透明度设置为255的UIID,以避免在递归中绘制其他背景。我将缩放图像更改为填充ScaleImageButton构造函数。我为构造函数使用了Label,它没有像UIId那样工作。我尝试了Style.BACKGROUND\u IMAGE\u SCALED、Style.BACKGROUND\u IMAGE\u SCALED\u FIT和Style.BACKGROUND\u IMAGE\u SCALED\u FILL和clean storage,但结果是一样的。您是否将bg透明度设置为255?