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







    版权声明:本文博客原创文章,博客,未经同意,不得转载。

  • 相关阅读:
    ZYNQ学习系列之GPIO
    ZYNQ7000系列学习
    新的开始
    mysql-笔记 精度
    mysql-笔记 聚合函数
    QTP自动化测试-连接数据库
    mysql create/insert
    QTP自动化测试-使用数据库-配置ODBC
    QTP自动化测试-在object repository manager中定位不到控件
    QTP自动化测试-调用函数
  • 原文地址:https://www.cnblogs.com/gcczhongduan/p/4754208.html
Copyright © 2020-2023  润新知