[英]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.