Relative Layout

layout:{
    type: 'relative'
}

Demo

In the demo below, the individual views, seekbars, form inputs etc are positioned and sized relative to each other and to its parent view.

SAMPLE
CODE

The relative layout is inspired by the Android relative layout. It arranges child views relative to each other. It encouraged you to use a shallow view hierarchy which can be important for performance.

To use the relative layout set layout.type to "relative"

layout: {
    type:'relative'
}

Arranging child views

type:relative is set on the parent view. The other properties of the relative layout should be set on child views.

Example: use layout.centerInParent to center a view inside it's parent view.

SAMPLE
CODE

Position attributes

Positional attributes are used to set the left, top and/or bottom right css attributes of the views.

The available attributes are listed below.

  • centerInParent {Boolean} - Center vertically and horizontally inside parent view.
  • centerHorizontal {Boolean} - Center horizontally inside parent view.
  • centerVertical {Boolean} - Center vertically inside parent view.
  • alignParentTop {Boolean} - Align at top edge of parent view.
  • alignParentBottom {Boolean} - Align bottom of this view with the bottom of parent view.
  • alignParentLeft {Boolean} - Align left in parent view.
  • alignParentRight {Boolean} - Right align inside parent view.
  • alignLeft {String} - Same left position as sibling with this id.
  • alignRight {String} - Same right position as sibling with this id.
  • alignTop {String} - Same top position as sibling with this id.
  • alignBottom {String} - Same bottom edge as sibling with this id.
  • leftOf {String} - Left of sibling view with this id.
  • rightOf {String} - Left of sibling view with this id.
  • above {String} - Above sibling view with this id.
  • below {String} - Below sibling view with this id.
  • absLeft {Number} - Absolute left position.
  • absRight {Number} - Absolute right position.
  • absTop {Number} - Absolute top position.
  • absBottom {Number} - Absolute bottom position.
  • offsetX {Number} - After positioning the view, offset left position with these number of pixels.
  • offsetY {Number} - After positioning the view, offset top position with these number of pixels.

Demo

SAMPLE
CODE

Size attributes

The size attributes are used to set width and height of the view.

  • width (Number|String) Pixel width, percentage size(example: width:"30%"), or "matchParent".
  • height (Number|String) Pixel height, percentage size or "matchParent".
  • sameWidthAs (String) Same width as sibling view with this id.
  • sameHeightAs (String) Same height as sibling view with this id.
  • fillRight (String) Span to the right edge of parent view.
  • fillDown (String) Span to the bottom edge of parent view.
  • fillUp (String) Span to top edge of parent view.
  • fillLeft (String) Span to left edge of parent view.
  • resize (Array) Make the view resizable in these directions(left|right|above|below).
  • minWidth (Number|String) Minimum width when resizable in pixels or percentage.
  • maxWidth (Number|String) Maximum width when resizable in pixels or percentage.
  • minHeight (Number|String) Minimum height when resizable in pixels or percentage.
  • maxHeight (Number|String) Maximum height when resizable in pixels or percentage.

Resize demo

SAMPLE
CODE

Avoid circular references

A Circular reference occurs when you have code like:

children:[
    {  id:'firstView', layout: { rightOf:'secondView' } },
    {  id:'secondView', layout: { leftOf:'firstView' } }
]

As you can see in this example, "firstView" want to be positioned relative to "secondView" while "secondView" wants to be positioned relative to "firstView". This is an error, and you will be warned in the browsers developer console when this occurs.

Generated 2016-12-02 19:27:14