2dx相对布局和Android非常类似。假设前完成Android它应该是easy入门。

        Size widgetSize = Director::getInstance()->getWinSize();Text* 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));addChild(alert);Layout* 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);Button* button_TopLeft = Button::create("animationbuttonnormal.png", "animationbuttonpressed.png");layout->addChild(button_TopLeft);RelativeLayoutParameter* rp_TopLeft = RelativeLayoutParameter::create();rp_TopLeft->setAlign(RELATIVE_ALIGN_PARENT_TOP_LEFT);button_TopLeft->setLayoutParameter(rp_TopLeft);//top center horizontalButton* button_TopCenter = Button::create("animationbuttonnormal.png","animationbuttonpressed.png");layout->addChild(button_TopCenter);RelativeLayoutParameter* rp_TopCenter = RelativeLayoutParameter::create();rp_TopCenter->setAlign(RELATIVE_ALIGN_PARENT_TOP_CENTER_HORIZONTAL);button_TopCenter->setLayoutParameter(rp_TopCenter);Button* button_TopRight = Button::create("animationbuttonnormal.png","animationbuttonpressed.png");layout->addChild(button_TopRight);RelativeLayoutParameter* rp_TopRight = RelativeLayoutParameter::create();rp_TopRight->setAlign(RELATIVE_ALIGN_PARENT_TOP_RIGHT);button_TopRight->setLayoutParameter(rp_TopRight);//left centerButton* button_LeftCenter = Button::create("animationbuttonnormal.png","animationbuttonpressed.png");layout->addChild(button_LeftCenter);RelativeLayoutParameter* rp_LeftCenter = RelativeLayoutParameter::create();rp_LeftCenter->setAlign(RELATIVE_ALIGN_PARENT_LEFT_CENTER_VERTICAL);button_LeftCenter->setLayoutParameter(rp_LeftCenter);//centerButton* buttonCenter = Button::create("animationbuttonnormal.png","animationbuttonnormal.png");layout->addChild(buttonCenter);RelativeLayoutParameter* rpCenter = RelativeLayoutParameter::create();rpCenter->setAlign(RELATIVE_CENTER_IN_PARENT);buttonCenter->setLayoutParameter(rpCenter);Button* button_RightCenter = Button::create("animationbuttonnormal.png","animationbuttonpressed.png");layout->addChild(button_RightCenter);RelativeLayoutParameter* rp_RightCenter = RelativeLayoutParameter::create();rp_RightCenter->setAlign(RELATIVE_ALIGN_PARENT_RIGHT_CENTER_VERTICAL);button_RightCenter->setLayoutParameter(rp_RightCenter);//left bottomButton* button_LeftBottom = Button::create("animationbuttonnormal.png","animationbuttonpressed.png");layout->addChild(button_LeftBottom);RelativeLayoutParameter* rp_LeftBottom = RelativeLayoutParameter::create();rp_LeftBottom->setAlign(RELATIVE_ALIGN_PARENT_LEFT_BOTTOM);button_LeftBottom->setLayoutParameter(rp_LeftBottom);//bottom centerButton* button_BottomCenter = Button::create("animationbuttonnormal.png","animationbuttonpressed.png");layout->addChild(button_BottomCenter);RelativeLayoutParameter* rp_BottomCenter = RelativeLayoutParameter::create();rp_BottomCenter->setAlign(RELATIVE_ALIGN_PARENT_BOTTOM_CENTER_HORIZONTAL);button_BottomCenter->setLayoutParameter(rp_BottomCenter);Button* button_RightBottom = Button::create("animationbuttonnormal.png","animationbuttonpressed.png");layout->addChild(button_RightBottom);RelativeLayoutParameter* rp_RightBottom = RelativeLayoutParameter::create();rp_RightBottom->setAlign(RELATIVE_ALIGN_PARENT_RIGHT_BOTTOM);button_RightBottom->setLayoutParameter(rp_RightBottom);

转载于:https://www.cnblogs.com/yxwkf/p/5035203.html

cocos2d-x3.0 相对布局(一)相关推荐

  1. 《Div+CSS 3.0网页布局案例精粹》扫描版[PDF]

    电驴资源 下面是用户共享的文件列表,安装电驴后,您可以点击这些文件名进行下载 [Div.CSS.3.0网页布局案例精粹].王大远.扫描版.rar详情 53.7MB 全选 53.7MB 下载地址(拷贝到 ...

  2. cocos2d中CCAnimation的使用(cocos2d 1.0以上版本)

    原文地址:cocos2d中CCAnimation的使用(cocos2d 1.0以上版本)作者:七贤林子 在cocos2d  0.9及以下版本中,CCAnimation中可以使用animationWit ...

  3. 【飞鸽传书3.0】飞鸽传书3.0关键字布局

    老站如果堆积那就是降权了.[飞鸽传书3.0]关键字的布局要讲究合理.特别是你的描述中的飞鸽传书3.0关键字布局,最好是包含在一句很顺利的话里面,而且出现不要超过三次为好.一般首页顶部会有导航栏目,这里 ...

  4. DISCUZ X3.0 积分增减以及记录

    http://www.bubuko.com/infodetail-663248.html DISCUZ X3.0 积分增减以及记录 1.调用source/function/function_core. ...

  5. android5.0协调布局CoordinatorLayout(第二篇CollapsingToolbarLayout效果实现原理讲解)原理

    上一篇中已经讲解了CoordinatorLayout.AppBarLayout.CollapsingToolbarLayout之间的关系,这一篇探索一下CollapsingToolbarLayout内 ...

  6. Discuz X3.0,X2.5最新帖子单页展示教程,附懒人包,站长基地zzjidi.com

    这是一个从X2移植过来的教程,现升级至X3.0,X2.5,教程分享给各位. DiscuzX2的版本可查看<最新回复.查看新帖单页显示 For Discuz!X2> 都知道Discuz默认的 ...

  7. cocos2d-x3.0中数据类型vector,map、value

    在3.0中,已经不再使用以前的ccarray,ccdictionary,ccint等从以前的oc继承过来的数据类型,转而加入了自己的数据结构,更加符合c++的开发习惯和思考模式,其中就包括了vecto ...

  8. 网站建设中最实用的扁平化2.0设计布局简析(干货)

    近年来网站建设迎来了扁平化2.0新时代,这周研究一些扁平化2.0设计师的移动端设计布局形式,整理分析了一些常用的布局形态,有兴趣的朋友们就来了解下吧 常用的移动端设计布局形式:不规则弧线布局.层叠式布 ...

  9. 设置flex-shrink:0. flex布局只占位,不占空间

    问题: 这个汉堡按钮把文字给压住了 解决方法: 在汉堡结构前面放一个空的 div元素进行占位 问题: 这个汉堡按钮把文字给压住了 解决方法: 在汉堡结构前面放一个空的 div元素进行占位 因为咱们添加 ...

最新文章

  1. 贪心算法--多处最优服务次序问题
  2. LeetCode中常用语言的一些基本方法记录
  3. python的闭包要素_Python的闭包
  4. MFC使用ADO对象开发数据库应用程序
  5. android 自定义心电图,Android自定义 View 练习 —— 心电图的绘制
  6. ZXing拍码后区分扫描到的是一维码、二维码、其他码
  7. HaaS Python 云端一体AI 车型识别功能
  8. pfc颗粒linux安装包,离散元颗粒流软件(PFC3D/PFC2D)
  9. 拼音输入法技巧-智能ABC
  10. 2017 年,最热开源静态网站生成器 TOP 20 揭晓!
  11. C#开发微信门户及应用(34)--微信裂变红包
  12. 小马激活手动分配磁盘_不要成为“单把小马”手动测试仪
  13. python抓取豆瓣电影
  14. php 微信公众号自定义菜单栏,php实现微信公众号创建自定义菜单
  15. [转载] 胡锡进:5000亿买一包爆米花 我不想让我的国家这样
  16. win10开机自动打开http://go.microsoft.com/fwlink/?LinkID=219472clcid=0x409
  17. 迅雷因版权问题不能访问
  18. Apache的配置文件详细解释
  19. windows sevrer2012 dns服务器安装配置
  20. 01-初识Node.js

热门文章

  1. UITextView: 响应键盘的 return 事件(收回键盘)
  2. redis aof持久化遇到的Can't open the append-only file Permissi
  3. 有效运维的 on-call 机制
  4. 盘点几种数据库的分页SQL的写法(转)
  5. 最大堆的Java实现
  6. 函数重载 覆盖 隐藏
  7. 北京学python 价格怎么样_北京学习Python需要多少钱
  8. 如何提升python编程能力_Python编程小白如何提升自己的编程能力
  9. VS2008中源文件与模块生成时的文件不同,仍要让调试器使用它吗
  10. python两个时间内的工作日_如何在Python中找到两个日期之间的星期一或任何其他工作日的数目?...