博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Cocos2d-x layout (二)
阅读量:6745 次
发布时间:2019-06-25

本文共 3013 字,大约阅读时间需要 10 分钟。

相对某个控件进行布局

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);                ImageView* imageView_Center = ImageView::create("scrollviewbg.png");        layout->addChild(imageView_Center);                RelativeLayoutParameter* rp_Center = RelativeLayoutParameter::create();        //给布局參数起名字,以便以后别的对象相对它布局        rp_Center->setRelativeName("rp_Center");        rp_Center->setAlign(RELATIVE_CENTER_IN_PARENT);        imageView_Center->setLayoutParameter(rp_Center);                //above center        ImageView* imageView_AboveCenter = ImageView::create("switch-mask.png");        layout->addChild(imageView_AboveCenter);                RelativeLayoutParameter* rp_AboveCenter = RelativeLayoutParameter::create();        //设置相对哪个对象布局        rp_AboveCenter->setRelativeToWidgetName("rp_Center");        rp_AboveCenter->setAlign(RELATIVE_LOCATION_ABOVE_CENTER);        imageView_AboveCenter->setLayoutParameter(rp_AboveCenter);                        //below center        ImageView* imageView_BelowCenter = ImageView::create("switch-mask.png");        layout->addChild(imageView_BelowCenter);                RelativeLayoutParameter* rp_BelowCenter = RelativeLayoutParameter::create();        rp_BelowCenter->setRelativeToWidgetName("rp_Center");        rp_BelowCenter->setAlign(RELATIVE_LOCATION_BELOW_CENTER);        imageView_BelowCenter->setLayoutParameter(rp_BelowCenter);                        //left center        ImageView* imageView_LeftCenter = ImageView::create("switch-mask.png");        layout->addChild(imageView_LeftCenter);                RelativeLayoutParameter* rp_LeftCenter = RelativeLayoutParameter::create();        rp_LeftCenter->setRelativeToWidgetName("rp_Center");        rp_LeftCenter->setAlign(RELATIVE_LOCATION_LEFT_OF_CENTER);        imageView_LeftCenter->setLayoutParameter(rp_LeftCenter);                                //right center        ImageView* imageView_RightCenter = ImageView::create("switch-mask.png");        layout->addChild(imageView_RightCenter);                RelativeLayoutParameter* rp_RightCenter = RelativeLayoutParameter::create();        rp_RightCenter->setRelativeToWidgetName("rp_Center");        rp_RightCenter->setAlign(RELATIVE_LOCATION_RIGHT_OF_CENTER);        imageView_RightCenter->setLayoutParameter(rp_RightCenter);

你可能感兴趣的文章
shell脚本变量
查看>>
Python中异步协程的使用方法介绍
查看>>
unity与安卓通讯的一些事儿
查看>>
IIS配置负载均衡
查看>>
python入门之python介绍
查看>>
轻量级HTTP服务器Nginx(入门篇)
查看>>
linux下apache服务搭建
查看>>
CSS学习4 - 例子CSS-sprities
查看>>
Cocos2d-x for WindowsPhone:万丈高楼亦可不需平地起
查看>>
https 原理理解
查看>>
centos7.x编译安装mysql5.7.16
查看>>
bzoj 1263: [SCOI2006]整数划分
查看>>
Format
查看>>
2018.12.14-dtoj3192: Smuggling Marbles
查看>>
基于WDF的PCI/PCIe接口卡Windows驱动程序(5)-如何为硬件移植驱动程序
查看>>
打印数字 形状有点得味
查看>>
Python_基础(命名,数据类型,循环)
查看>>
轻松精通数据库管理之道——运维巡检之七(日志)
查看>>
QT学习之QString和QByteArray转换
查看>>
关于收费插件许可证
查看>>