一节说你需要使用精灵:@H_301_3@http://code.google.com/webtoolkit/doc/latest/DevGuideClientBundle.html#ImageResource
repeatStyle is an enumerated value@H_301_3@ that is used in combination with@H_301_3@ the@sprite directive to indicate that@H_301_3@ the image is intended to be tiled
所以,现在我需要添加一个精灵指令..哪里?@H_301_3@研究精灵,我来到这里:@H_301_3@http://code.google.com/webtoolkit/doc/latest/DevGuideClientBundle.html#Image_Sprites
该示例指示创建两个文件:
> MyCssResource@H_301_3@> MyResources
我在哪里可以写:
@sprite .mySpriteClass {gwt-image:@H_301_3@ “imageAccessor”; other: property;}
?
一些更多的引用可供参考:
@sprite is sensitive to the FooBundle@H_301_3@ in which the CSSResource is declared;@H_301_3@ a sibling ImageResource method named@H_301_3@ in the @sprite declaration will be@H_301_3@ used to compose the background sprite.
解决方法
interface MyResources extends ClientBundle { @Source("myImage.png") @ImageOptions(repeatStyle = RepeatStyle.BOTH) ImageResource myImage(); @Source("myCss.css") MyCssResource myCss(); } interface MyCssResource extends CssResource { String myBackground(); }
所以现在有两种使用从MyResources获得的ImageResource的方法。第一个是使用@sprite指令将其附加到CSS规则。 myCss.css:
@sprite .myBackground { gwt-image: "myImage"; /* Additional CSS rules may be added. */ }
然后,myBackground类的任何内容都将myImage作为其背景。所以,使用UiBinder,例如:
<ui:UiBinder> <!-- Preamble omitted for this example. --> <ui:with field="myResources" type="com.mycompany.MyResources"/> <g:FlowPanel styleName="{myResources.myCss.myBackground}"/> </ui:UiBinder>
还可以使用定义的ImageResource直接实例化Image对象。 UiBinder:
<ui:UiBinder> <!-- Preamble omitted for this example. --> <ui:with field="myResources" type="com.mycompany.MyResources"/> <g:Image resource="{myResources.myImage}"/> </ui:UiBinder>
没有UiBinder:
MyResources myResources = GWT.create(MyResources.class); Image myImage = new Image(myResources.myImage());