GWT StackLayoutPanel:动态和自动高度
我正在使用 StackLayoutPanel 来显示 gmail 中对话的堆叠电子邮件,其中标头是发件人,子级是电子邮件的正文。由于其动态特性,我只能在代码中估计堆栈的高度。为了估计主体的高度,我可以获取客户端窗口的宽度,然后粗略地猜测主体占据了多少行。但这很费力,而且很可能是错误的。
我的问题是:对于 GWT API 2.2,StackLayoutPanel 有没有办法知道并自动设置当前显示的子项(加上其标题和其他标题)的显示高度?
恐怕不是,所以我尝试过其他的事情,但也失败了。我尝试过:
将 StackLayoutPanel 放入 ScrollPanel 中:
- 如果我不在代码中设置堆栈的大小,神秘的是我只能看到第一个堆栈的标头,而看不到它的主体,也看不到其他标头。
- 如果我确实设置了它,那么我就会遇到身体高度估计的问题。
不在 ScrollPanel 内: 堆栈自动获取剩余窗口空间的大小,但由于标头太多,这些标头相互重叠并叠加。
另外,StackLayoutPanel 的默认行为似乎是在分配空间的最末尾显示其余标头,而不是在前一个标头的子级之后。有可能改变这一点吗?
对此的帮助将不胜感激。
//我知道类似的问题是 这个,但我想我对此进行了扩展。
I'm using a StackLayoutPanel to show stacked emails of a conversation a la gmail where the header is the sender and the child the email's body. For the dynamic nature of this, I can only estimate the height of my stack in code. To estimate the body's height I could get the client's window's width then roughly guess how many lines the body occupies. But this is laborious and likely to be wrong.
My question is: is there a way for the StackLayoutPanel, as for GWT API 2.2, to know and so set automatically the height in display of the current shown child (plus its header and the other headers)?
I'm afraid not so I've tried other things that also, however, fail. I've tried:
Put the StackLayoutPanel inside a ScrollPanel:
- If I don't set in code a stack's size, mysteriously I can only see the first stack's header and nothing more, not its body, nor other headers.
- If I do set it, then I have the problem of the body's height estimation.
Not inside a ScrollPanel:
the stack gets automatically the size of remaining window's space, but with too many headers these overlap and superimpose each other.
Also, it seems the default behaviour for StackLayoutPanel is to show the rest of headers at the very end of the allocated space, not just after the before's header's child. Is it possible to change this?
Help on this would be much appreciated.
//I know a similar question is this but I think I expand on it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你是对的,你确实扩展了上一个问题,答案很简单: stackLayoutPanel.setHeight((40*numChildren + 200)+"px");
200px 的主体大小取决于内容,并且足够大,因此 StackLayoutPanel 可能不会为您裁剪。
我认为您将使用 StackLayoutPanel 的壁橱是使用固定的主体宽度并在主体内使用 ScrollPanel (而不是 SP 内的 SLP)。这样所有的邮件都可以显示ScrollPanel中的所有内容。
由于这是一个妥协,替代方案是实现您自己的小部件。我可能会使用 VerticalPanel 作为底层小部件,只隐藏和显示 div(同时保持标题始终可见)
You are right, you do expand on the previous question where the answer is a simple: stackLayoutPanel.setHeight((40*numChildren + 200)+"px");
The 200px body size is dependent on the content and enough so that StackLayoutPanel is probably not going to cut it for you.
I think the closet you are going to come with StackLayoutPanel is to use a fixed body width and use a ScrollPanel INSIDE the body (not SLP inside SP). This way all emails can show all content in ScrollPanel.
Since this is a bit of a compromise, the alternative is to just implement your own widget. I would probably use a VerticalPanel as the underlying widget and just hide and display div's (while keeping the headers visible all the time)
也许可以使用自定义小部件来实现此目的,该小部件将包装一堆
DisclosurePanel
,以便一次只能显示其中一个。Maybe it's possible to accomplish this with a custom widget that would wrap a bunch of
DisclosurePanel
s so that only one of them can be shown at a time.如果扩展 StackLayoutPanel,并使用可见小部件高度以及面板标题高度的任意数字编写 resize() 方法:
然后在面板标题上添加一个单击处理程序,在单击时调用此方法,堆栈面板动态调整大小以显示所选面板。
If you extend the StackLayoutPanel, and write a resize() method, using the visible widget height, plus some arbitrary number for the height of the panel headers:
Then add a click handler on the panel header that calls this method when clicked, the stack panel resizes dynamically to display the selected panel.