[英]libGDX ScrollPane slightly scrolls back automatically when I scroll to the bottom
我想创建一个带有多个按钮的ScrollPane。 ScrollPane必须垂直滚动。
滚动到底部时遇到2个问题:1)即使滚动到最大,最后一个按钮也无法完全显示,底部却缺少一小部分。 2)当我释放鼠标按钮时,滚动到底部后,ScrollPane会向后滚动一点,最后一个按钮不再显示。
我在Google上找不到与这些问题有关的任何东西。 滚动到底部时,如何强制ScrollPane完全显示最后一个按钮? 释放鼠标按钮后,如何防止ScrollPan向后滚动?
public class ShopScreen implements Screen{
final MyGdxGame game;
OrthographicCamera camera;
Stage stage;
ScrollPane scrollPane;
Table table;
Texture texture1, texture2, texture3, texture4, texture5, texture6;
ImageButton button1, button2, button3, button4, button5, button6;
public ShopScreen(final MyGdxGame gam){
game = gam;
Constants.ecran = EcranEnum.Shop;
camera = new OrthographicCamera();
camera.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
stage = new Stage();
table = new Table();
scrollPane = new ScrollPane(table);
texture1 = new Texture(Gdx.files.internal("Images/Option1.png"));
texture2 = new Texture(Gdx.files.internal("Images/Option2.png"));
texture3 = new Texture(Gdx.files.internal("Images/Option3.png"));
texture4 = new Texture(Gdx.files.internal("Images/Option4.png"));
texture5 = new Texture(Gdx.files.internal("Images/Option5.png"));
texture6 = new Texture(Gdx.files.internal("Images/Option6.png"));
button1 = new ImageButton(new Image(texture1).getDrawable());
button2 = new ImageButton(new Image(texture2).getDrawable());
button3 = new ImageButton(new Image(texture3).getDrawable());
button4 = new ImageButton(new Image(texture4).getDrawable());
button5 = new ImageButton(new Image(texture5).getDrawable());
button6 = new ImageButton(new Image(texture6).getDrawable());
table.setFillParent(true);
table.defaults().width(Gdx.graphics.getWidth()/2.5f).height(Gdx.graphics.getHeight()/(8*Gdx.graphics.getHeight()/Gdx.graphics.getWidth()));
table.add(button1).row();
table.add(button2).row();
table.add(button3).row();
table.add(button4).row();
table.add(button5).row();
table.add(button6).row();
scrollPane.setX(Gdx.graphics.getWidth()/2-scrollPane.getWidth()/2);
scrollPane.setY(Gdx.graphics.getHeight()/2-scrollPane.getHeight()/2);
button1.addListener(new ClickListener(){
@Override
public void clicked(InputEvent event, float x, float y) {
System.out.println("Test");
}
});
}
@Override
public void render(float delta) {
Gdx.gl.glClearColor(0.281f, 0.602f, 0.844f, 0);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.act();
stage.draw();
}
@Override
public void resize(int width, int height) {
// TODO Auto-generated method stub
}
@Override
public void show() {
stage.addActor(scrollPane);
Gdx.input.setInputProcessor(stage);
}
@Override
public void hide() {
// TODO Auto-generated method stub
}
@Override
public void pause() {
// TODO Auto-generated method stub
}
@Override
public void resume() {
// TODO Auto-generated method stub
}
@Override
public void dispose() {
// TODO Auto-generated method stub
}
非常感谢您的帮助 !
尝试这个。
public class ShopScreen implements Screen{
final MyGdxGame game;
OrthographicCamera camera;
Stage stage;
ScrollPane scrollPane;
//container is new
Table table, container;
Texture texture1, texture2, texture3, texture4, texture5, texture6;
ImageButton button1, button2, button3, button4, button5, button6;
public ShopScreen(final MyGdxGame gam){
game = gam;
Constants.ecran = EcranEnum.Shop;
camera = new OrthographicCamera();
camera.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
stage = new Stage();
//Add
container = new Table();
table = new Table();
stage.addActor(container);
container.setFillParent(true);
final ScrollPane scrollPane = new ScrollPane(table);
float myPadTop = Gdx.graphics.getHeight()/2-scrollPane.getHeight()/2;
float myPadBottom = Gdx.graphics.getHeight()/2-scrollPane.getHeight()/2;
scrollPane.setFlickScroll(true);
container.add(scrollPane).padTop(myPadTop).padBottom(myPadBottom);
table.pad(10).defaults().expandX().space(4);
//
texture1 = new Texture(Gdx.files.internal("Images/Option1.png"));
texture2 = new Texture(Gdx.files.internal("Images/Option2.png"));
texture3 = new Texture(Gdx.files.internal("Images/Option3.png"));
texture4 = new Texture(Gdx.files.internal("Images/Option4.png"));
texture5 = new Texture(Gdx.files.internal("Images/Option5.png"));
texture6 = new Texture(Gdx.files.internal("Images/Option6.png"));
button1 = new ImageButton(new Image(texture1).getDrawable());
button2 = new ImageButton(new Image(texture2).getDrawable());
button3 = new ImageButton(new Image(texture3).getDrawable());
button4 = new ImageButton(new Image(texture4).getDrawable());
button5 = new ImageButton(new Image(texture5).getDrawable());
button6 = new ImageButton(new Image(texture6).getDrawable());
//table.setFillParent(true);//Remove
//table.defaults().width(Gdx.graphics.getWidth()/2.5f).height(Gdx.graphics.getHeight()/(8*Gd//x.graphics.getHeight()/Gdx.graphics.getWidth()));//Remove
table.add(button1).row();
table.add(button2).row();
table.add(button3).row();
table.add(button4).row();
table.add(button5).row();
table.add(button6).row();
//scrollPane.setX(Gdx.graphics.getWidth()/2-scrollPane.getWidth()/2);//Remove
//scrollPane.setY(Gdx.graphics.getHeight()/2-scrollPane.getHeight()/2);//Remove
button1.addListener(new ClickListener(){
@Override
public void clicked(InputEvent event, float x, float y) {
System.out.println("Test");
}
});
}
@Override
public void render(float delta) {
Gdx.gl.glClearColor(0.281f, 0.602f, 0.844f, 0);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.act(Gdx.graphics.getDeltaTime());
stage.draw();
}
@Override
public void resize(int width, int height) {
// TODO Auto-generated method stub
}
@Override
public void show() {
//stage.addActor(scrollPane);
Gdx.input.setInputProcessor(stage);
}
您所说的关于不回去的话,从未看过,因为我喜欢回去。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.