gpt4 book ai didi

GWT UiBinder 和图像 Sprite

转载 作者:行者123 更新时间:2023-12-04 19:13:42 25 4
gpt4 key购买 nike

我无法让 CSS 图像 Sprite 出现在 GWT UiBinder 中。我做了评论 how do i use image sprites in GWT? ,但发现我已经在做建议的事情了。

我有一个 ui.xml , ClientBundleCssBundle 的接口(interface)嵌套接口(interface)和一个css文件。

ui.xml:

<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui">
<ui:with field="resources"
type="edu.wts.upholdingthetruth.poweroftheword.client.resources.POWResources" />

<g:FlowPanel width="100%" styleName="{resources.sprites.underMenuGlow}" />
</ui:UiBinder>

客户端包:
public interface POWResources extends ClientBundle {
public static final POWResources INSTANCE = GWT.create(POWResources.class);

@Source("site1/undertopglow.png")
ImageResource underTopGlow();

@Source("sprites.css")
public Sprites sprites();

public interface Sprites extends CssResource {

String underMenuGlow();
}

// other stuff
}

sprites.css:
@sprite .underMenuGlow {gwt-image: "underTopGlow"}

所以,我编译了我的应用程序(它没有提示),在浏览器中,我的图像丢失了。当我在 Chrome 的开发人员工具中查看该页面时,我看到相应的 div 引用了混淆的 css 类,但我无法在任何地方找到该类定义。

另一方面,我能够使用 <g:Image resource="{resources.underTopGlow}" /> 显示图像.

我是否缺少通过这样的 css sprites 显示图像的步骤?

最佳答案

您必须调用 ensureInjected()在您的 CssResource 上在你的代码中的某个地方;任何一个:

POWResources.INSTANCE.sprites().ensureInjected();

或者
@UiField POWResources resources;

resources.sprites().ensureInjected();

或者,如果你不与其他代码共享样式/图像,你可以用 UiBinder 从 ui:style 创建的隐式替换你的 ClientBundle和 ui:image (然后 UiBinder 会为你调用 ensureInjected):
<ui:style>
@sprite .underMenuGlow {gwt-image: "underTopGlow"}
</ui:style>
<ui:image field="underTopGlow" src="site1/undertopglow.png" />

<span class="{style.underMenuGlow}">foo</span>

关于GWT UiBinder 和图像 Sprite ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6236673/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com