2016-06-16 4 views
0

背景を持つスクロールペインを作成しようとしています。しかし、私はバックグラウンドがスクロールペインの領域以上を占めるようにしたい。たとえば、ここに私のバックグラウンドで、赤色で、私はスクロールペインになりたいところです: enter image description hereLibgdx - スクロールペインの背景を大きくする

どのようにすることができます:

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); 

答えて

1

は、その内容がご希望の背景の領域内に収まるように取得するために、外のテーブルパッドです。

背景に9パッチのドロアブルを使用すると、外側の表のパディングが自動的に実行されます(または、スクロールペインを置くセルをパディングすることもできます)。また、あなたのスキンJsonでTextureRegionDrawableを指定し、それをバックグラウンドとして使用することもできます。これにより、テーブルを自動的に埋め込むこともできます。

skin.getDrawable(drawableName);を使用すると、スキンからテクスチャ領域ドロワブルを簡単に取得できます。リージョンからドロアブルを作成するためだけに中間イメージを作成する必要はありません。

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

次に、あなたのコード内で:ここ

あなたはJSONで明示的なパディングとTextureRegionDrawableを作成する方法をです container.setBackground(skin.getDrawable("main-panel-horz-padded"));

関連する問題