获取 UiBinder 小部件以内联显示而不是块显示
我试图让我的 UiBinder 定义的小部件内联显示,但我不能。我当前的代码是:
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder' xmlns:g='urn:import:com.google.gwt.user.client.ui'>
<ui:style>
.section {
border: 1px solid #000000;
width: 330px;
padding: 5px;
display: run-in;
}
</ui:style>
<g:HTMLPanel>
<div class="{style.section}">
<div ui:field="titleSpan" class="{style.title}" />
<div class="{style.contents}">
<g:VerticalPanel ui:field="messagesPanel" />
</div>
</div>
</g:HTMLPanel>
</ui:UiBinder>
就小部件内部的外观而言,这工作得很好,但我想将一堆这些小部件放入 FlowPanel 中,并在调整窗口大小时让它们流动。 HTMLPanel 是一个 div,但我无法分配显示属性。我无法强制使用样式名称,因为以下内容会引发错误:
<g:HTMLPanel styleNames="{style.section}">
并且我可以分配其他样式,但它不应用显示设置。
<g:HTMLPanel addStyleNames="{style.section}">
这会按预期显示边框并设置大小,但它不流动。 Firebug显示div上的样式为边框、宽度和填充,但不显示。
有没有办法在 UiBinder 中制作一个小部件,以便它可以内联显示而不是块显示?如果是这样,我可以使其与内部有一个 VerticalPanel 兼容吗(我可以在不使整个小部件成为纯 HTML 且没有任何 GWT 小部件的情况下做到这一点)吗?
PS:我看到问题2257924 但最近没有任何答案,而且他似乎专注于获取标签,而不是专门获取内联布局。我不直接关心,如果我能让我的小部件的顶级标签内联流动,我很高兴。
I'm trying to get my UiBinder-defined widget to display inline, but I can't. My current code is:
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder' xmlns:g='urn:import:com.google.gwt.user.client.ui'>
<ui:style>
.section {
border: 1px solid #000000;
width: 330px;
padding: 5px;
display: run-in;
}
</ui:style>
<g:HTMLPanel>
<div class="{style.section}">
<div ui:field="titleSpan" class="{style.title}" />
<div class="{style.contents}">
<g:VerticalPanel ui:field="messagesPanel" />
</div>
</div>
</g:HTMLPanel>
</ui:UiBinder>
This works fine in terms of how the widget looks internally, but I want to throw a bunch of these widgets into a FlowPanel and have them flow when the window is resized. The HTMLPanel is a div, but I can't get the display attribute to assign. I can't force the style name, since the following throws an error:
<g:HTMLPanel styleNames="{style.section}">
And I can assign an additional style, but it doesn't apply the display setting.
<g:HTMLPanel addStyleNames="{style.section}">
This displays the border and sets the size, as expected, but it doesn't flow. Firebug shows the styles on the div are border, width, and padding, but no display.
Is there a way to make a widget in UiBinder so that it'll display inline instead of block? And if so, can I make it compatible with having a VerticalPanel inside (can I do it without making the entire widget pure HTML without any GWT widgets)?
PS: I saw question 2257924 but it hasn't had any answers lately, and he seems to be focused on getting a tag, not specifically getting inline layout. I don't care directly about , if I can just get the top-level tag for my widget to flow inline, I'm happy.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看来您的问题是由使用
display: run-in
而不是更“标准”的display: inline
引起的。 IE 和 Firefox 不支持run-in
,Firebug 在添加时似乎会修剪样式。尝试将样式更改为
display: inline
(或inline-block
如果您想要块的某些属性,例如宽度,但要注意 IE +inline-block
的怪癖)。It seems your problem is caused by using
display: run-in
instead of the more "standard"display: inline
. IE and Firefox don't supportrun-in
and it seems that Firebug prunes the style upon adding.Try changing the style to
display: inline
(orinline-block
if you want some properties of a block, like width, but beware of the quirks of IE +inline-block
).它应该是
,而不是
- styleNames 是一个拼写错误(它出现在 UiBinder 文档中,所以我确信这就是您从哪里获得的)。 styleName 是正确的使用方式。此外,Igor Klimer 是正确的,您应该使用
display: inline
或display: inline-block
而不是display: run-in
。一般来说,您可以通过在 UIObject 类,属性名称就是 XXX。因此,
UIObject
有一个setStyleName
方法,您可以使用名为styleName
的属性来访问该方法。It should be
<g:HTMLPanel styleName="{style.section}">
, not<g:HTMLPanel styleNames="{style.section}">
- styleNames is a typo (which appears in the UiBinder docs, so I'm sure that's where you got it from). styleName is the correct thing to use.Also, Igor Klimer is correct that you should use
display: inline
ordisplay: inline-block
rather thandisplay: run-in
.In general, you can tell the available attribute names by looking for setXXX methods on the UIObject class, and the attribute name is just the XXX. So,
UIObject
has asetStyleName
method, which you access using the attribute calledstyleName
.