3

My scrollPane is not scrolling when i add ScrollPaneStyle, does anyone know why is happinging?

scroller = new ScrollPane( myWidget , skin);
        scroller.setBounds(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
        this.addActor(scroller);
        scroller.setLayoutEnabled( true );
        scroller.setCancelTouchFocus( true );
        ScrollPaneStyle paneStyle = new ScrollPaneStyle();
        Texture tex = new Texture(Gdx.files.internal(filepath + "page.png"));
        tex.setWrap(Texture.TextureWrap.Repeat, Texture.TextureWrap.ClampToEdge);
        paneStyle.background = new SpriteDrawable( new Sprite(tex));

        scroller.setScrollbarsOnTop(true);
        scroller.setStyle(paneStyle);
Daahrien
  • 10,190
  • 6
  • 39
  • 71

3 Answers3

3

You have to add stage.act(); to render after you draw the stage.

pklas
  • 31
  • 2
1

after you init the scrollpane you should call this first

mScrollPane.layout();
junfeng
  • 59
  • 4
1

I met the same problem as you did.

when I add the scroll panel to a Table, it can scroll as I exptected.

ScrollPane pane2 = new ScrollPane(mytable, style);
style.background = new TextureRegionDrawable(scrollAtalas.findRegion("default-rect"));
pane2.setScrollingDisabled(false, true);
pane2.setSize(w, h);
final Table table = new Table();
table.setFillParent(true);
table.add(pane2).fill();

stage.addActor(table);

You can refer the test code from libgdx test also.

zhibin
  • 59
  • 5