zoukankan      html  css  js  c++  java
  • Cocos2d-x layout (二)

    相对某个控件进行布局

    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);







  • 相关阅读:
    Token的生成和检验
    MD5和SHA加密实现
    服务器读取客户端数据
    服务器上传和下载文件
    NOI模拟题4 Problem B: 小狐狸(fox)
    NOI模拟题4 Problem A: 生成树(mst)
    混凝土数学第四章之数论学习笔记
    混凝土数学第二章和式之有限微积分 ( 离散微积分 ) 学习笔记
    网络流相关学习笔记
    NOI模拟题1 Problem A: sub
  • 原文地址:https://www.cnblogs.com/hrhguanli/p/3951080.html
Copyright © 2011-2022 走看看