2013-03-14 79 views
0

我遇到問題讓libgdxs scrollpane控件工作。下面的代碼顯示了帶有標籤的簡單佈局的控制設置,滾動窗格內的項目列表以及按鈕。問題是我的滾動窗格沒有顯示除vScroll/vScrollKnob ninepatch(那個小白色方塊) 以外的其他東西,它看起來像這樣:libgdx scrollpane不顯示

screenshot

 private void setupLayout() 
{ 
    String[] listEntries = {"1","2","3","4","5"}; 
    ListStyle listStyle = new ListStyle(); 
    NinePatch example = new NinePatch(new Texture(Gdx.files.internal("data/example.9.png")));  
    listStyle.selectedPatch = example; 
    listStyle.font = new BitmapFont(); 
    mList = new List(listEntries,listStyle); 

    ScrollPaneStyle paneStyle = new ScrollPaneStyle(); 
    paneStyle.vScroll = example; 
    paneStyle.vScrollKnob = example;   
    mListScroll = new ScrollPane(mList,paneStyle); 
    mListScroll.setScrollingDisabled(true, false); 
    mListScroll.width = 500; 
    mListScroll.height = 500; 

    LabelStyle ls = new LabelStyle(); 
    ls.font = new BitmapFont(); 
    ls.fontColor = new Color(1.0f, 1.0f, 1.0f, 1.0f); 
    mLabel = new Label("Label", ls);  

    TextButtonStyle buttonStyle = new TextButtonStyle(); 
    buttonStyle.font = new BitmapFont(); 
    mButton = new TextButton("Button",buttonStyle); 

    Table table = new Table(); 
    table.add(mLabel); 
    table.row(); 
    table.add(mButton); 
    table.row(); 
    table.add(mListScroll); 
    mStage.addActor(table); 
} 

它工作正常,如果我不使用該滾動窗格和直接添加列表,表是這樣的:

Table table = new Table(); 
    table.add(mLabel); 
    table.row(); 
    table.add(mButton); 
    table.row(); 
    table.add(mList);    //changed mListScroll(scrollpane class) to mList(List class) 
    mStage.addActor(table); 

screenshot

但隨後它會伸出當物品太多時,我的屏幕底部。我在這裏做錯了什麼?我需要在scrollpane上設置另一個參數嗎?

回答

1

我相信你遇到的問題是你如何將東西添加到表中。我建議下面的代碼,而不是你是如何做的:

Table table = new Table(); 
table.add(mLabel); 
table.row(); 
table.add(mButton); 
table.row(); 

// Changing the table layout size itself. 
table.add(mListScroll).size(500, 500); 

mStage.addActor(table); 

欲瞭解更多更詳細的說明,請參閱TableLayout這裏的快速啓動您展示更多如何使用表格佈局對象。