[英]libgdx scrollpane doesn't display
我在使libgdxs滚动窗格控件正常工作时遇到问题。 下面的代码显示了带有标签,滚动窗格中的项目列表和按钮的简单布局的控件设置。 问题是我的滚动窗格没有显示任何内容,除了vScroll / vScrollKnob ninepatch(那个小的白色正方形),它看起来像这样:
屏幕截图 。
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);
但是,当有太多项目时,它将延伸到屏幕底部。 我在这里做错了什么? 我需要在滚动窗格上设置另一个参数吗?
我相信您遇到的问题是如何向表中添加内容。 我建议使用以下代码代替您的工作方式:
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。此处的快速入门向您展示了如何使用表来布置对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.