【问题标题】:Using non-CSS constants in GWT UiBinder在 GWT UiBinder 中使用非 CSS 常量
【发布时间】:2012-09-20 03:28:30
【问题描述】:

我正在尝试在 GWT 的 UiBinder XML 中使用常量或定义。我找到的所有问题和答案都与 CSS 常量有关,在元素中使用 @def 注释,但这不是我需要的。举个例子:

<g:Button width="60" height="24">Hello</g:Button>

如果我的页面上有 50 个按钮,所有按钮的尺寸都相同,我不想按照上面的说明设置每个按钮的尺寸。如果我想更改宽度,我必须对页面上的所有按钮执行此操作。所以,我正在寻找的是这样的:

<g:Button width="{myWidth}" height="{myHeight}">Hello</g:Button>

常量“myWidth”和“myHeight”在 UiBinder XML 文件的开头某处指定。我试过这样做,但我无法让它工作。

有什么想法吗?

【问题讨论】:

    标签: gwt uibinder


    【解决方案1】:

    A.这就是你的做法:

    <ui:with field="styleConstants" type="...constants.StyleConstants" />
    
    <g:Button width="{styleConstants.myWidth}" height="{styleConstants.myHeight}">Hello</g:Button>
    

    显然,StyleConstants 应该有 myWidth() 和 myHeight() 方法。

    B.将相同大小设置为 50 个按钮是错误的。这就是 CSS 类的用途。定义一个 CSS 类并将其分配给每个按钮:

    <g:Button styleName="button">Hello</g:Button>
    

    您可以为此目的使用外部 CSS 文件或 CSS 资源。

    【讨论】:

    • 例如,StyleConstants 可以扩展 com.google.gwt.i18n.shared.Constants
    • @ThomasBroyer:我很好奇。现有的com.google.gwt.i18n.shared.Constants 有什么好处?
    • @Ümit: I18N;如果您在某些语言环境中需要稍微宽/窄的东西,因为您知道文本将无法正确显示(众所周知,德语的标签通常比英语的标签长)。那和/或在属性文件中指定您的常量值。
    • @ThomasBroyer:啊,我明白了。没想到。谢谢你的解释。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多