繁体   English   中英

Libgdx-为滚动窗格创建更大的背景

[英]Libgdx - Creating larger background for scrollpane

我正在尝试创建一个具有背景的滚动窗格。 但是,我希望背景占用的空间超过滚动窗格的面积。 例如,这是我的背景,红色是我想要滚动窗格所在的位置:

滚动窗格

但是,当我添加按钮时,得到以下结果: 在此处输入图片说明

如何将实际的滚动窗格部分限制为一个部分(上图中以红色显示)?

这是我到目前为止所拥有的。 我开玩笑地用空格/填充,但是没有产生任何好的结果:

Skin skin = Resources.getSkin(Resources.SKIN_JSON);
container = new Table();
container.setSize(Resources.VIRTUAL_WIDTH, Resources.VIRTUAL_HEIGHT);
this.addActor(container);
Table table = new Table();
// table.debug();

final ScrollPane scroll = new ScrollPane(table, skin);
table.pad(10).defaults().expandX().space(4);
table.setSize(Resources.VIRTUAL_WIDTH, Resources.VIRTUAL_HEIGHT);

container.add(scroll).expand().fill().colspan(1);
container.row().space(10).padBottom(10);

Image background = new Image(Resources.getAtlas(Resources.SKIN_ATLAS).findRegion("main-panel-horz"));
container.setBackground(background.getDrawable());

TextButton button1 = new TextButton("Button1", skin);
table.add(button1);

table.row();
TextButton button2 = new TextButton("button2", skin);
table.add(button2);

table.row();
TextButton button3 = new TextButton("button3", skin);
table.add(button3);

table.row();
TextButton button4 = new TextButton("button4", skin);
table.add(button4);

您需要做的就是填充外部表格,使其内容适合您想要的背景区域。 (或者,您也可以填充放入滚动窗格的单元格。)

如果您使用9色可绘制背景作为背景,则外部表格的填充将自动为您完成。 您还可以在外观Json中指定TextureRegionDrawable并将其用作背景。 那也将允许您自动填充桌子。

您可以使用skin.getDrawable(drawableName);从皮肤轻松获取纹理区域可skin.getDrawable(drawableName); -无需创建中间图像,只需创建区域之外的可绘制对象即可。

这是在json中使用显式填充创建TextureRegionDrawable的方法:

com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable: {
    main-panel-horz-padded: { region: main-panel-horz, leftWidth: 50, rightWidth: 50, topHeight: 50, bottomHeight: 50 }
},

然后在您的代码中: container.setBackground(skin.getDrawable("main-panel-horz-padded"));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM