码迷,mamicode.com
首页 > 其他好文 > 详细

Libgdx 之CheckBox ScrollPane

时间:2016-06-16 14:43:52      阅读:185      评论:0      收藏:0      [点我收藏+]

标签:

CheckBox 复选框

CheckBox extends TextButton,其实CheckBox就是继承自TextButton,然后里面添加了 Image 控件,可以知道CheckBox的状态是否被选中, checkBox.isChecked()

ScrollPane 滑动列表

ScrollPane extends WidgetGroup, 默认大小是(150, 150),大小也是由preferred size来决定的。
其实这2个控件很简单,通过源码很容易理解怎样使用

public class CheckTest extends ApplicationAdapter {

    CheckBox checkBox;
    ScrollPane scrollPane;

    Stage stage;
    Skin skin;

    @Override
    public void create() {
        stage = new Stage();
        Gdx.input.setInputProcessor(stage);

        skin = new Skin(Gdx.files.internal("uiskin.json"));

        checkBox = new CheckBox("CheckBox", skin);
        checkBox.addListener(new ChangeListener() {

            @Override
            public void changed(ChangeEvent event, Actor actor) {
                if (checkBox.isChecked()) {
                    Gdx.app.log("TAG", "box is checked");
                } else {
                    Gdx.app.log("TAG", "box is unchecked");
                }
            }
        });

        final List<String> list2 = new List<String>(skin);
        String[] items = {"item5", "item6", "item7", "item8"};
        list2.setItems(items);
        list2.pack();
        scrollPane = new ScrollPane(list2, skin);
        scrollPane.setHeight(scrollPane.getHeight()*0.4f);
        scrollPane.setPosition(0, 40 + checkBox.getHeight());
        scrollPane.addListener(new ChangeListener() {

            @Override
            public void changed(ChangeEvent event, Actor actor) {
                // 其实是内部的Actor来处理的响应函数
                System.out.println(""+list2.getSelected());
            }

        });

        stage.addActor(checkBox);
        stage.addActor(scrollPane);
    }

    @Override
    public void render() {
        Gdx.gl.glClearColor(0.39f, 0.58f, 0.92f, 1.0f);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

        stage.act();
        stage.draw();
    }

    @Override
    public void dispose() {
        stage.dispose();
        skin.dispose();
    }

技术分享

Libgdx 之CheckBox ScrollPane

标签:

原文地址:http://blog.csdn.net/zqiang_55/article/details/51685616

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!