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







  • 相关阅读:
    随手记
    jira默认是jira_user用户组的用户有登录jira的权限 上海
    loadrunner11安装 上海
    虚拟机增加内存方法 上海
    centos6中安装VMware Tools 上海
    linux安装过程中遇到的一些问题总结 上海
    C语言指针方法对字符串进行去重 上海
    在linux环境下搭建JDK+JAVA+Mysql,并完成jforum的安装 上海
    关于pl/sql打开后database为空的问题解决办法 上海
    字符串表达式求值(支持多种类型运算符)
  • 原文地址:https://www.cnblogs.com/hrhguanli/p/3951080.html
Copyright © 2011-2022 走看看