Layout

  1. #include"ui/CocosGUI.h"
  2. using namespace ui;
  3. Layout *layout = Layout::create();
  4. //设置布局类型为平面相对布局
  5. layout->setLayoutType(LayoutType::RELATIVE);
  6. //设置大小
  7. layout->setContentSize(Size(280, 150));
  8. //设置锚点
  9. layout->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
  10. //设置背景颜色为单一固定颜色
  11. layout->setBackGroundColorType(Layout::BackGroundColorType::SOLID);
  12. //设置背景颜色为绿色
  13. layout->setBackGroundColor(Color3B::GREEN);
  14. layout->setPosition(Vec2(100, visibleSize.height/2));
  15. //创建一个图片
  16. ImageView * imageview = ImageView::create("scrollviewbg.png");
  17. layout->addChild(imageview);
  18. RelativeLayoutParameter * rp_Center = RelativeLayoutParameter::create();
  19. rp_Center->setRelativeName("rp_Center");
  20. //中间
  21. rp_Center->setAlign(RelativeLayoutParameter::RelativeAlign::CENTER_IN_PARENT);
  22. //上方 rp_Center->setAlign(RelativeLayoutParameter::RelativeAlign::LOCATION_ABOVE_CENTER);
  23. //下方 rp_Center->setAlign(RelativeLayoutParameter::RelativeAlign::LOCATION_BELOW_CENTER);
  24. //左边 rp_Center->setAlign(RelativeLayoutParameter::RelativeAlign::LOCATION_LEFT_CENTER);
  25. //右边 rp_Center->setAlign(RelativeLayoutParameter::RelativeAlign::LOCATION_RIGHT_CENTER);
  26. imageview->setLayoutParameter(rp_Center);
  27. this->addChild(layout);





posted @ 2017-01-09 11:22  feizuzu  阅读(346)  评论(0编辑  收藏  举报