[英]libgdx scrollpane doesn't display
I'm having issues getting libgdxs scrollpane control to work. 我在使libgdxs滚动窗格控件正常工作时遇到问题。 The code below shows control setup for a simple layout with a label, a List of items inside a scrollpane, and a button. 下面的代码显示了带有标签,滚动窗格中的项目列表和按钮的简单布局的控件设置。 The problem is my scroll pane doesn't show anything other than the vScroll/vScrollKnob ninepatch (that tiny white square) it just looks like this: 问题是我的滚动窗格没有显示任何内容,除了vScroll / vScrollKnob ninepatch(那个小的白色正方形),它看起来像这样:
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);
}
It works as expected if i don't user the scroll pane and add the list directly to the table like this: 如果我不使用滚动窗格并直接将列表添加到表中,则它将按预期工作:
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);
But then it will extend out the bottom of my screen when there are too many items. 但是,当有太多项目时,它将延伸到屏幕底部。 What am I doing wrong here? 我在这里做错了什么? Is there another parameter i need to set on the scrollpane? 我需要在滚动窗格上设置另一个参数吗?
I believe the issue you are having is how you are adding things to the table. 我相信您遇到的问题是如何向表中添加内容。 I would suggest the following code instead of how you are doing it: 我建议使用以下代码代替您的工作方式:
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);
For more a more detailed explanation refer to TableLayout the quick start here shows you more how using tables for laying out objects. 有关更多详细说明,请参见TableLayout。此处的快速入门向您展示了如何使用表来布置对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.