2015-04-04 59 views
1

是否可以在应用程序运行时更改NiftyGui中面板的大小?我想这样的代码: //initNiftyGui - 如何更改面板的大小

mainScreen = new ScreenBuilder("main") {{ 
    controller(sc); 
    layer(new LayerBuilder("foreground"){{ 
     childLayoutCenter(); 
     panel(new PanelBuilder("p1"){{ 
      childLayoutAbsoluteInside(); 
      backgroundColor("#00ff00"); 
      width("100%"); 
      height("100%"); 
      padding("10px"); 
      panel(new PanelBuilder("p4"){{ 
       x("100%");y("100%"); 
       height("20%"); 
       width("20%"); 
       backgroundColor("#0000ff"); 
      }}); 
     }}); 
    }}); 
    }}.build(nifty); 

//update()

Element f = nifty.getCurrentScreen().findElementById("p4"); 
f.getParent().layoutElements(); 
f.setHeight(f.getHeight() + 300); 

并没有什么正在发生变化。

+0

你试过了吗? – d3dave 2015-04-04 21:19:44

+0

当然,我失败了。 – gusili 2015-04-05 04:20:23

回答

3

好的,我解决了这个问题。我正在使用错误的方法。解决方案是使用,而不是setConstraintHeight(SizeValue)setHeight(int)

`Element f = nifty.getCurrentScreen().findElementById("p4"); 
f.getParent().layoutElements(); 
f.setConstraintHeight(new SizeValue(f.getHeight() + 5 + "px"));`