【问题标题】:How do I display a widget (HorizontalPanel) on top of another widget (Image) in GWT?如何在 GWT 中的另一个小部件(图像)之上显示一个小部件(Horizo​​ntalPanel)?
【发布时间】:2012-05-03 01:09:03
【问题描述】:

我试图让 Horizo​​ntalPanel 中的两个按钮显示在图像顶部。不是在上面,因为您会看到按钮,然后再往下看页面并看到图像,但是您看图像并且上面有按钮。

这是我目前在 Page.ui.xml 文件中的代码:

 <g:FocusPanel ui:field="profileImagePanel" addStyleNames="{style.headerImage}">
     <g:AbsolutePanel addStyleNames="{style.innerImagePanel}">
         <g:Image ui:field="profileImage" addStyleNames="{style.profileImage}"/>
         <g:HorizontalPanel ui:field="imageEditButtons" addStyleNames="{style.imageEditButtons}">
             <w:MultiUseButton ui:field="clearImage" addStyleNames="{style.change}" type="secondary" text="{i18n.clearImage}" visible="false"/>
             <w:MultiUseButton ui:field="changeImage" type="secondary" text="{i18n.changeImage}" visible="false"/>
         </g:HorizontalPanel>
     </g:AbsolutePanel>
 </g:FocusPanel>

样式是:

.headerImage {
    position: absolute;
    top: 0;
    left: 0;
    width: 150px;
}

.profileImage {
    width: 150px;
    position: relative;
}

.change {
    float: right;
}

.headerImage a {
    display: block;
}

.imageEditButtons {
    width:100%;
}

.innerImagePanel {
    width:150px;
}

我尝试过使用 FlowPanel 而不是 AbsolutePanel,但这不起作用。我试过制作 profileImage position:relative 和 imageEditButtons position:absolute 但这会破坏页面其余部分的整个显示。我也尝试设置 imageEditButtons margin-top:-20px 但它位于图像下方而不是顶部。如果我将 Horizo​​ntalPanel 放在 Image 之前的 AbsolutePanel 中,则按钮位于图像上方,如果我尝试更改上边距,则会将按钮和 Image 向下移动。

我的想法已经不多了。任何有关如何使这项工作的建议将不胜感激。

【问题讨论】:

  • 为什么你的标签Button的属性visible处于false状态?
  • 它们一开始是隐藏的,然后当用户进入编辑模式时,它们在相关的 .java 文件中被设置为 true。
  • 好吧,在这种情况下没有问题。
  • 将图像作为背景不太适合我们使用图像的方式。请参阅我对您的回答的评论。

标签: css gwt uibinder gwt-widgets


【解决方案1】:

应用样式background-image 而不是使用小部件Image。以下是我对 UiBinder 文件内容的想象:

<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
     xmlns:g="urn:import:com.google.gwt.user.client.ui">
   <ui:style>
       /* requirement style */
       .myPanel {
           width: 200px; /* width of your background image */
           height: 400px; /* height of your background image */     
           background-image: url(images/myimage.jpg); /* your image */
           background-repeat: no-repeat;
       }

       /* optional style */
       .myButton {
           margin: 10px;
           width: 80px;
           height: 40px;
       }
   </ui:style>
   <g:HTMLPanel>
       <g:FocusPanel ui:field="profileImagePanel">
           <g:AbsolutePanel addStyleNames="{style.myPanel}">
               <g:HorizontalPanel ui:field="imageEditButtons">
                   <g:Button ui:field="clearImage" text="clear image" addStyleNames="{style.myButton}" />
                   <g:Button ui:field="changeImage" text="second button" addStyleNames="{style.myButton}" />
               </g:HorizontalPanel>
           </g:AbsolutePanel>
       </g:FocusPanel>
   </g:HTMLPanel>

用您的w:MultiUseButton 替换我的标签g:Button 并添加所需的其他样式。您可以在 css 文件中引入的样式。结果,你应该得到你想要的。在这种情况下,不需要 AbsolutePanel。简单的 FlowPanel 也适用。

【讨论】:

  • 原来,我需要将 .innerImagePanelposition 属性设置为 relative,然后将 .imageEditButtons 设置为 @ 987654327@。但是你的回答也可以,所以我接受了。 :)
  • 我也使用 FlowPanel 而不是 AbsolutePanel。好建议。
猜你喜欢
  • 2019-02-19
  • 1970-01-01
  • 2019-01-30
  • 2011-01-18
  • 2019-01-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-11-07
相关资源
最近更新 更多