#include"ui/CocosGUI.h"using namespace ui;Layout *layout = Layout::create(); //设置布局类型为平面相对布局 layout->setLayoutType(LayoutType::RELATIVE); //设置大小 layout->setContentSize(Size(280, 150)); //设置锚点 layout->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT); //设置背景颜色为单一固定颜色 layout->setBackGroundColorType(Layout::BackGroundColorType::SOLID); //设置背景颜色为绿色 layout->setBackGroundColor(Color3B::GREEN); layout->setPosition(Vec2(100, visibleSize.height/2)); //创建一个图片 ImageView * imageview = ImageView::create("scrollviewbg.png"); layout->addChild(imageview); RelativeLayoutParameter * rp_Center = RelativeLayoutParameter::create(); rp_Center->setRelativeName("rp_Center"); //中间 rp_Center->setAlign(RelativeLayoutParameter::RelativeAlign::CENTER_IN_PARENT); //上方 rp_Center->setAlign(RelativeLayoutParameter::RelativeAlign::LOCATION_ABOVE_CENTER); //下方 rp_Center->setAlign(RelativeLayoutParameter::RelativeAlign::LOCATION_BELOW_CENTER); //左边 rp_Center->setAlign(RelativeLayoutParameter::RelativeAlign::LOCATION_LEFT_CENTER); //右边 rp_Center->setAlign(RelativeLayoutParameter::RelativeAlign::LOCATION_RIGHT_CENTER); imageview->setLayoutParameter(rp_Center); this->addChild(layout);