cocos2d-x3.0 ListView

来源:未知 责任编辑:责任编辑 发表时间:2014-05-26 10:56 点击:

.h

#include "cocos2d.h"
#include "cocos-ext.h"
#include "ui/CocosGUI.h"
#include "cocostudio/CocoStudio.h"
USING_NS_CC;

USING_NS_CC_EXT;
using namespace ui;

  void selectedItemEvent(Ref *pSender, ListViewEventType type);

.cpp

     
         layout = Layout::create();
        layout->setSize(Size(widgetSize.width, widgetSize.height));
       
        //横向排列,这里类似Android里的线性布局
        //layout->setLayoutType(LAYOUT_RELATIVE);
        /*以图片为背景*/
        layout->setBackGroundImageScale9Enabled(true);
        layout->setBackGroundImage("green_edit.png");
        
        layout->setPosition(Point(0,0));
        addChild(layout);
        
        
         alert = Text::create("Layout", "fonts/Marker Felt.ttf", 30 );
        alert->setColor(Color3B(159, 168, 176));
        alert->setPosition(Point(widgetSize.width / 2.0f,
                                 widgetSize.height / 2.0f - alert->getSize().height * 3.075f));
        
        layout->addChild(alert);

        /******************************************************************************************/
        
        std::vector  _array;
        for (int i = 0; i < 20; i++) {
           
            _array.push_back( StringUtils::format("listView_item_%d",i));
        }
        
        ListView* listView = ListView::create();
        //SCROLLVIEW_DIR_VERTICAL  SCROLLVIEW_DIR_HORIZONTAL   
        listView->setDirection(SCROLLVIEW_DIR_VERTICAL);
        listView->setTouchEnabled(true);
        listView->setBounceEnabled(true);
        listView->setBackGroundImage("green_edit.png");
        listView->setBackGroundImageScale9Enabled(true);
        listView->setSize(Size(480, 260));
        listView->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
        listView->addEventListenerListView(this, listvieweventselector(LayoutTest::selectedItemEvent));
        
        layout->addChild(listView);
        
        //create model
        Button* default_button = Button::create("backtotoppressed.png","backtotopnormal.png");
        default_button->setName("Title Button");
        
        Layout* default_item = Layout::create();
        default_item->setTouchEnabled(true);
        default_item->setSize(default_button->getSize());
        default_button->setPosition(Point(default_item->getSize().width / 2.0f, default_item->getSize().height / 2.0f));
        default_item->addChild(default_button);
        
        //set model
        listView->setItemModel(default_item);
        
        //add default item
        
        ssize_t count = _array.size();
        for (int i = 0; i < count / 4; ++i) {
            listView->pushBackDefaultItem();
        }
        
        //insert default item
        for (int i = 0; i < count / 4; ++i) {
            listView->insertDefaultItem(0);
        }
        
        //add custom item
        
        for (int i = 0; i < count / 4; ++i) {
            Button* custom_button = Button::create("button.png","buttonHighlighted.png");
            custom_button->setName("Title Button");
            custom_button->setScale9Enabled(true);
            custom_button->setSize(default_button->getSize());
            
            Layout* custom_item = Layout::create();
            custom_item->setSize(custom_button->getSize());
            custom_button->setPosition(Point(custom_item->getSize().width / 2.0f, custom_item->getSize().height / 2.0f));
            custom_item->addChild(custom_button);
            listView->pushBackCustomItem(custom_item);
        }
        
        //insert custom item
        Vector
	
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
用户名: 验证码:点击我更换图片
最新评论 更多>>

推荐热点

  • cocos2d-x学习笔记(19)--label 、label atlas
  • cocos2d-x学习笔记(23)--地图的使用3--CCTMXLayer
  • Cocos2d-x学习(一):HelloWorld
  • cocos2dx在xcode下开发,编译到android上(2)
  • cocos2d 设置屏幕默认方向
  • Cocos2d-x 2.0 之 Actions “三板斧” 之一
  • cocos2d-x学习笔记(22)--地图的使用2(TMX) --Z-Order、AnchorPoi
  • cocos2d-x学习笔记(18)--游戏打包(windows平台)
  • cocos2d-x学习笔记(16)--spritesheet(精灵表单)
网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
Copyright © 2008-2015 计算机技术学习交流网. 版权所有

豫ICP备11007008号-1