Layout relative to a widget
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); // horizontal arrangement, similar to the linear layout-> setLayoutType (LAYOUT_RELATIVE) in Android;/* use the image as the background */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 (); // name the layout parameter, so that other objects can layout 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 (parameters); RelativeLayoutParameter * rp_AboveCenter = RelativeLayoutParameter: create (); // set the relative object layout rp_AboveCenter-> setRelativeToWidgetName ("rp_Center"); rp_AboveCenter-> setAlign (parameters); 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-> Centers ("rp_Center"); rp_BelowCenter-> setAlign (centers); 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-> Centers ("rp_Center "); rp_LeftCenter-> setAlign (values); imageView_LeftCenter-> setLayoutParameter (rp_LeftCenter); // right center ImageView * imageView_RightCenter = ImageView: create ("switch-mask.png "); layout-> addChild (imageView_RightCenter); Parameters * rp_RightCenter = RelativeLayoutParameter: create (); rp_RightCenter-> parameters ("rp_Center"); rp_RightCenter-> setAlign (rule ); imageView_RightCenter-> setLayoutParameter (rp_RightCenter );