(libgdx学习)ScrollPane(使用ScrollPane来创建一个横向滚动条)
一、官方demo(他这个也是纵向滚动的)
/******************************************************************************** Copyright 2011 See AUTHORS file.* * Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at* * http://www.apache.org/licenses/LICENSE-2.0* * Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* See the License for the specific language governing permissions and* limitations under the License.******************************************************************************/package com.badlogic.gdx.tests;import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.tests.utils.GdxTest;public class ScrollPane2Test extends GdxTest {Stage stage;Skin skin;public void create () {stage = new Stage(0, 0, false);Gdx.input.setInputProcessor(stage);skin = new Skin(Gdx.files.internal("data/uiskin.json"));ScrollPane pane2 = new ScrollPane(new Image(new Texture("data/group-debug.png")), skin);pane2.setScrollingDisabled(false, true);// pane2.setCancelTouchFocus(false);pane2.addListener(new InputListener() {public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {event.stop();return true;}});Table mytable = new Table();mytable.debug();/*** table里面有5行,每行就一个Image*/mytable.add(new Image(new Texture("data/group-debug.png")));mytable.row();mytable.add(new Image(new Texture("data/group-debug.png")));mytable.row();mytable.add(pane2).size(100);//在scrollpane里面又嵌套了一个ScrollPanemytable.row();mytable.add(new Image(new Texture("data/group-debug.png")));mytable.row();mytable.add(new Image(new Texture("data/group-debug.png")));ScrollPane pane = new ScrollPane(mytable, skin);pane.setScrollingDisabled(true, false);// pane.setCancelTouchFocus(false);if (false) {// This sizes the pane to the size of it's contents.pane.pack();// Then the height is hardcoded, leaving the pane the width of it's contents.pane.setHeight(Gdx.graphics.getHeight());} else {// This shows a hardcoded size.pane.setWidth(300);pane.setHeight(Gdx.graphics.getHeight());}stage.addActor(pane);}public void render () {Gdx.gl.glClearColor(0, 0, 0, 1);Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);stage.act(Gdx.graphics.getDeltaTime());stage.draw();Table.drawDebug(stage);}public void resize (int width, int height) {stage.setViewport(width, height, false);}@Overridepublic void dispose () {stage.dispose();skin.dispose();}public boolean needsGL20 () {return false;}
}
自己做的demo(横向滚动...其所谓的横向滚动和纵向滚动的最主要的差别就在于一个table里面的行数和列数的不同)
package com.example.groupactiontest;import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.Input.Peripheral;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table;public class MyGame implements ApplicationListener {Stage stage;@Overridepublic void create() {stage = new Stage();Table table = new Table();Skin skin = new Skin(Gdx.files.internal("uiskin.json"));//创建并初始化一个skinScrollPane pane = new ScrollPane(table,skin);//创建并初始化一个ScrollPaneImage image = new Image(new Texture(Gdx.files.internal("group-debug.png")));pane.setSize(image.getWidth()* 3, image.getHeight()+10);//设置ScrollPane的宽度和高度pane.setScrollingDisabled(false, true);//设置是否可上下、左右移动..这里设置了横向可移动、纵向不可移动../*** 其实就是创建了一个横向滚动条...* 创建一个table,里面只有1行,一行中有10个image*/table.row();for(int i = 0 ; i < 10 ; ++i){table.add(new Image(new Texture(Gdx.files.internal("group-debug.png"))));//这里显示了往table里面添加一个组件
// table.add(image);//add()的时候应该写new Image(),而不应该直接写image,邹泽只会显示一个框}
// pane.pack();//将屏幕设置为一屏里面能够装下的东西的大小.这时候就不能滚动看到其他东西了...stage.addActor(pane);//直接将ScrollPane添加到stage里面Gdx.input.setInputProcessor(stage);}@Overridepublic void dispose() {// TODO Auto-generated method stub}@Overridepublic void pause() {// TODO Auto-generated method stub}@Overridepublic void render() {Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);stage.act();stage.draw();}@Overridepublic void resize(int arg0, int arg1) {// TODO Auto-generated method stub}@Overridepublic void resume() {// TODO Auto-generated method stub}}
三、效果图
四、源码下载
http://download.csdn.net/detail/caihongshijie6/7105429
(libgdx学习)ScrollPane(使用ScrollPane来创建一个横向滚动条)相关推荐
- 【itext学习之路】--1.创建一个简单的pdf文档
来源:https://blog.csdn.net/tomatocc/article/details/80666011 iText是著名的开放源码的站点sourceforge一个项目,是用于生成PDF文 ...
- maven 学习笔记(三)创建一个较复杂的 eclipse+android+maven 工程
前面maven 学习笔记(二)已经说过了怎样通过插件创建一个简单的工程,有了前面的基础,创建一个较复杂的工程就容易了很多.同样是通过已经有了插件,同样如果插件系统中并未存在,还是需要通过Add Arc ...
- 我的Go语言学习之旅七:创建一个GUI窗体
在上次中,刚刚学过了 弹窗效果,这里再接着学习一下如何创建一个窗体. 还是老路子,先上代码: package mainimport ( "github.com/lxn/go-winapi& ...
- Extjs6 --- 学习笔记(1)创建一个新项目
原公司使用的前端框架是Extjs,于是系统学习了Extjs的4和6.旧东家的项目主要为后台管理系统,因此对前端界面UI的要求并不高,侧重于数据的展示与处理 ,刚开始使用的是Extjs4,后升级成6. ...
- 学习UE4动画蓝图:创建一个射击姿势并使用
目标 本篇的目标是从一个包含射击的动画序列中创建一个射击姿势,并让角色可以随时切换成"射击姿势".我的工程上接<使用UE4动画混合空间实现侧向和后退移动>,不过理论上只 ...
- VUE学习(一)、创建一个Vue应用。
<html> <head><title>Tiny</title> </head> <body><!-- 将库添加到这里 - ...
- 我的Go语言学习之旅八:创建一个简单的WEB服务器
因为一直在做WEB程序,所以更关注WEB界的发展,这里就用GO做了一个简单的WEB服务器,直接看例子吧 package main import ( "fmt" "net/ ...
- Node.js 学习笔记--- (2)创建一个简单的博客工程
1. 新建一个工程 切换到工作盘,输入: $ cd d:\blog $ express -e blog 2. 安装所需要的模块 $ cd blog && npm install 3. ...
- java liferay_Liferay 6.1开发学习(二):创建一个Portlet工程 | IT人生录
胡老师:你好,我创建过程中,workspace的.log报这个错,但sdk的sdk.log提示创建成功.怎么处理,谢谢.详细错误日志见下: !ENTRY org.apache.ivyde.eclips ...
最新文章
- java包装_Java基础之神奇的包装类(一)
- matplotlib 散点图和折线图画在一起_使用matplotlib.pyplot画折线图
- 原生ajax+php上传图片的简单实现
- 拒绝了对对象 'XXX' (数据库 'XXX',架构 'dbo')的 SELECT 权限
- 三种css样式表及其优先级
- 编译实验(三)目标代码生成
- 快速定位Product assignment block里对应的修改逻辑使用的function module
- 命令执行——命令执行漏洞及(四)
- hdu4699-Editor【对顶栈】
- 常见的 HTTP 状态代码及原因
- php curl exec ch,PHP curl_exec函数的用法实例详解
- mysql 联表比对,MySQL联表查询详解/超详细mysql left join,right join,inner join用法分析比较...
- 字符串json中函数的定义与解析
- 集成学习——机器学习(周志华)
- 推荐系统(6):推荐算法之基于内容的推荐算法
- 【公式识别神器】Mathpix Snip 安装及其使用教程
- word2007 去背景底色
- 开热点给电脑消耗大吗_电脑连热点流量消耗大吗
- HBuilder开发App
- 【2021全国高校计算机能力挑战赛C++题目】17.信息整理 某机房上线了一套系统,和每台计算机都相连,以便监控各计算机相关外设的运行状态。