Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scroll Listener on Scroll Pane Libgdx

Tags:

scroll

libgdx

I am using a scroll pane to show a list of items. I want to add a Scroll Listener on the pane so that I can load more items Dynamically to the pane once it hits the bottom edge;

I tried to add an InputListener and override onScroll but is not working for me

like image 438
Rahul Verma Avatar asked Nov 30 '14 09:11

Rahul Verma


2 Answers

this is a simple test, I hope I understood your question

In Your Class.

..//
yourScrollPane.addListener(new EventListener() {

    @Override
    public boolean handle(Event event) {
        // TODO Auto-generated method stub

        System.out.println("Event % "+yourScrollPane.getScrollPercentY());

        if(yourScrollPane.getScrollPercentY() == 1f){
            addImageButton();
        }

        return false;
    }
});

}

private void addImageButton(){

    //Add actor in scroll
    yourTableInScrollPane.add(button2).row();
    yourTableInScrollPane.add(button3).row();
    yourTableInScrollPane.add(button4).row();

    //table.invalidate();
}
like image 52
Angel Angel Avatar answered Nov 16 '22 08:11

Angel Angel


I found another relevant solution which I would like to share :

ScrollPane scrollPane;
Table scrollTable
float lastScrollY = 0;
.
.
.
scrollTable = new Table();
this.scrollPane = new ScrollPane(scrollTable){
        @Override
        public void act(float delta) {
            super.act(delta);
            if(lastScrollY!=scrollPane.getScrollY()){
                lastScrollY = scrollPane.getScrollY();
                processScrolling();
            }

        }
    };
like image 3
Rahul Verma Avatar answered Nov 16 '22 07:11

Rahul Verma