如何检测视图是否完全呈现? [英] How to detect if a View is fully rendered?

查看:139
本文介绍了如何检测视图是否完全呈现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在视图中显示了几个GWT小部件。



该视图包含如下内容:

  FlowPanel mainPanel = new FlowPanel(); 
RootPanel.get()。add(mainPanel);
标签标签=新标签(test);
mainPanel.add(label);
FlowPanel otherPanel = new FlowPanel();
mainPanel.add(otherPanel);

mainPanel在视图完全渲染后获取其最终高度。我需要在渲染过程完成后从mainPanel获取高度值。



这是我迄今为止所做的:

  new Timer(){

@Override
public void run(){
int height = $(mainPanel )。高度();
//用mainPanel高度做
}
} .schedule(300);

Noite:$(mainPanel)是使用 GWTQuery
我设置了一个定时器,希望在定时器触发时视图渲染过程完成。我想这不是一个非常聪明的解决方案。



如何检测视图是否完全呈现以获得mainPanel的最终高度?



编辑:



我也试过使用:

  @Override 
保护void onReveal(){
super.onReveal();
Scheduler.get()。scheduleDeferred(new ScheduledCommand(){

@Override
public void execute(){
// get mainPanel height is incorrect
}
});
}

但似乎渲染没有完成,所以mainPanel没有正确的高度。

编辑:



移动和桌面使用SDM时。我创建了一个演示项目( https://github.com/confile/GWT-2.7- Scheduler-Test )来显示问题。

我在这里为此问题创建了另一个问题: https://stackoverflow.com/questions/27128787/gwt-2-7-scheduler-works-different-on-mobile-and-desktop-in- sdm

解决方案

Gwt本身为您提供了一个解决方案。它是 onLoad() 。您可以覆盖它。



示例。如果您想知道FlowPanel的小部件何时呈现,您可以使用

  FlowPanel flowPanel = new FlowPanel(){
@Override
protected void onLoad()
{
//在这里做你的东西
}};


I have a couple of GWT widgets which are displayed in a view.

The view contains content like this:

FlowPanel mainPanel = new FlowPanel();
RootPanel.get().add(mainPanel);
Label label = new Label("test");
mainPanel.add(label);
FlowPanel otherPanel = new FlowPanel();
mainPanel.add(otherPanel);

The mainPanel gets its final height after the view has been fully rendered. I need to get the value of height from the mainPanel after the render process is completed.

Here is what I do so far:

    new Timer() {

        @Override
        public void run() {
            int height = $(mainPanel).height();
            // do something with the mainPanel height
        }
    }.schedule(300);    

Noite: $(mainPanel) is the use of GWTQuery. I set a timer to hope that the view render process is completed when the timer fires. I suppose this is not a very clever solution.

How can I detect if the view is fully rendered in order to get the final height of the mainPanel?

Edit:

I also tried to use:

@Override
protected void onReveal() {
    super.onReveal();
    Scheduler.get().scheduleDeferred(new ScheduledCommand() {

        @Override
        public void execute() {
            // get mainPanel height is incorrect
        }
    });
}

but it seems that the rendering was not completed so the mainPanel did not have the correct height.

Edit:

It seems that the Scheduler works different on mobile and desktop when using SDM. I created a demo project (https://github.com/confile/GWT-2.7-Scheduler-Test) to show the problem.

I created another question for this issue here: https://stackoverflow.com/questions/27128787/gwt-2-7-scheduler-works-different-on-mobile-and-desktop-in-sdm

解决方案

Gwt itself gives you a hook to do it. It is onLoad(). You can override it.

Example. If you want to know when widgets of a FlowPanel are rendered, you can use

FlowPanel flowPanel = new FlowPanel(){
                      @Override
                      protected void onLoad()
                      {
                        //Do your stuff here
                      }};

这篇关于如何检测视图是否完全呈现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆