Scroll Listener on Scroll Pane Libgdx

自作多情 提交于 2019-12-10 13:59:34

问题


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


回答1:


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



回答2:


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

        }
    };


来源:https://stackoverflow.com/questions/27211992/scroll-listener-on-scroll-pane-libgdx

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!