2015-07-01 57 views
0

我有一個窗口,其中包含文本字段和一個用於獲取用戶輸入的按鈕。 最初的窗口看起來很好,如下所示。Scene2d小工具將無法正確調整大小

http://i.stack.imgur.com/ZDchq.png

當我調整窗口,該窗口被描繪爲如下所示的窗口的細但小工具元件被部分拉伸。

http://i.stack.imgur.com/NTpBN.png

這裏是我的我的Screenshow()功能代碼:

@Override 
public void show() { 
    // TODO Auto-generated method stub 
    game.assetManager.load("data/secondBackground.pack", TextureAtlas.class); 
    game.assetManager.finishLoading(); 

    stage = new Stage(); 
    TextureAtlas backgroundAtlas = game.assetManager.get("data/secondBackground.pack", TextureAtlas.class); 
    secondBackground = new Image(backgroundAtlas.findRegion("secondBackground")); 

    stage.addActor(secondBackground); 
    secondBackground.setFillParent(true); 
    Color secondBackgroundColor = secondBackground.getColor(); 
    secondBackground.setColor(secondBackgroundColor.r, secondBackgroundColor.g, secondBackgroundColor.b, 0.5f); 

    skin = new Skin(Gdx.files.internal("data/uiskin.json")); 
    Gdx.input.setInputProcessor(stage); 

    final TextField textFieldNickName = new TextField("", skin); 
    textFieldNickName.setMessageText("Nick Name"); 
    textFieldNickName.setAlignment(Align.center); 

    TextFieldStyle textFieldStyle = new TextFieldStyle(); 

    FileHandle fontFile = Gdx.files.internal("data/arial.ttf"); 
    FreeTypeFontGenerator generator = new FreeTypeFontGenerator(fontFile); 
    FreeTypeFontParameter parameter = new FreeTypeFontParameter(); 
    parameter.size = 55; 
    parameter.genMipMaps = true; 
    FreeTypeBitmapFontData fontData = generator.generateData(parameter); 
    BitmapFont ftFont = generator.generateFont(parameter); 
    generator.dispose(); 
    textFieldStyle.font=ftFont; 
    textFieldStyle.fontColor=Color.WHITE; 
    textFieldStyle.cursor = skin.newDrawable("cursor"); 
    textFieldNickName.setStyle(textFieldStyle); 

    Button okButton = new TextButton("OK",skin); 

    Window nickNameWindow = new Window("Enter your nick name", skin); 
    nickNameWindow.setPosition(0, 0); 
    nickNameWindow.defaults().spaceBottom(10); 
    nickNameWindow.row().fill().expandX(); 

    nickNameWindow.add(textFieldNickName).minWidth(stage.getWidth()/3).expandX().fillX(); 
    nickNameWindow.row(); 
    nickNameWindow.add(okButton).minWidth(100).expandX().fillX(); 
    nickNameWindow.pack(); 
    //nickNameWindow.setMovable(false); 
    stage.addActor(nickNameWindow); 
    nickNameWindow.setX(stage.getWidth()/2-nickNameWindow.getWidth()/2); 
    nickNameWindow.setY(stage.getHeight()/2+stage.getHeight()/4-nickNameWindow.getHeight()/2); 

} 

我做得不對或這是libgdx的錯誤嗎?

回答

相關問題