Android APIs
public static class

RelativeLayout.LayoutParams

extends ViewGroup.MarginLayoutParams
java.lang.Object
   ↳ android.view.ViewGroup.LayoutParams
     ↳ android.view.ViewGroup.MarginLayoutParams
       ↳ android.widget.RelativeLayout.LayoutParams

Class Overview

Per-child layout information associated with RelativeLayout.

Summary

XML Attributes
Attribute Name Related Method Description
android:layout_above Positions the bottom edge of this view above the given anchor view ID. 
android:layout_alignBaseline Positions the baseline of this view on the baseline of the given anchor view ID. 
android:layout_alignBottom Makes the bottom edge of this view match the bottom edge of the given anchor view ID. 
android:layout_alignEnd Makes the end edge of this view match the end edge of the given anchor view ID. 
android:layout_alignLeft Makes the left edge of this view match the left edge of the given anchor view ID. 
android:layout_alignParentBottom If true, makes the bottom edge of this view match the bottom edge of the parent. 
android:layout_alignParentEnd If true, makes the end edge of this view match the end edge of the parent. 
android:layout_alignParentLeft If true, makes the left edge of this view match the left edge of the parent. 
android:layout_alignParentRight If true, makes the right edge of this view match the right edge of the parent. 
android:layout_alignParentStart If true, makes the start edge of this view match the start edge of the parent. 
android:layout_alignParentTop If true, makes the top edge of this view match the top edge of the parent. 
android:layout_alignRight Makes the right edge of this view match the right edge of the given anchor view ID. 
android:layout_alignStart Makes the start edge of this view match the start edge of the given anchor view ID. 
android:layout_alignTop Makes the top edge of this view match the top edge of the given anchor view ID. 
android:layout_alignWithParentIfMissing If set to true, the parent will be used as the anchor when the anchor cannot be be found for layout_toLeftOf, layout_toRightOf, etc. 
android:layout_below Positions the top edge of this view below the given anchor view ID. 
android:layout_centerHorizontal If true, centers this child horizontally within its parent. 
android:layout_centerInParent If true, centers this child horizontally and vertically within its parent. 
android:layout_centerVertical If true, centers this child vertically within its parent. 
android:layout_toEndOf Positions the start edge of this view to the end of the given anchor view ID. 
android:layout_toLeftOf Positions the right edge of this view to the left of the given anchor view ID. 
android:layout_toRightOf Positions the left edge of this view to the right of the given anchor view ID. 
android:layout_toStartOf Positions the end edge of this view to the start of the given anchor view ID. 
[Expand]
Inherited XML Attributes
From class android.view.ViewGroup.MarginLayoutParams
From class android.view.ViewGroup.LayoutParams
[Expand]
Inherited Constants
From class android.view.ViewGroup.LayoutParams
Fields
public boolean alignWithParent When true, uses the parent as the anchor if the anchor doesn't exist or if the anchor's visibility is GONE.
[Expand]
Inherited Fields
From class android.view.ViewGroup.MarginLayoutParams
From class android.view.ViewGroup.LayoutParams
Public Constructors
RelativeLayout.LayoutParams(Context c, AttributeSet attrs)
RelativeLayout.LayoutParams(int w, int h)
RelativeLayout.LayoutParams(ViewGroup.LayoutParams source)
RelativeLayout.LayoutParams(ViewGroup.MarginLayoutParams source)
RelativeLayout.LayoutParams(RelativeLayout.LayoutParams source)
Copy constructor.
Public Methods
void addRule(int verb)
Adds a layout rule to be interpreted by the RelativeLayout.
void addRule(int verb, int anchor)
Adds a layout rule to be interpreted by the RelativeLayout.
String debug(String output)
Returns a String representation of this set of layout parameters.
int[] getRules()
Retrieves a complete list of all supported rules, where the index is the rule verb, and the element value is the value specified, or "false" if it was never set.
void removeRule(int verb)
Removes a layout rule to be interpreted by the RelativeLayout.
void resolveLayoutDirection(int layoutDirection)
This will be called by requestLayout().
[Expand]
Inherited Methods
From class android.view.ViewGroup.MarginLayoutParams
From class android.view.ViewGroup.LayoutParams
From class java.lang.Object

XML Attributes

android:layout_above

Positions the bottom edge of this view above the given anchor view ID. Accommodates bottom margin of this view and top margin of anchor view.

Must be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

This corresponds to the global attribute resource symbol layout_above.

Related Methods

android:layout_alignBaseline

Positions the baseline of this view on the baseline of the given anchor view ID.

Must be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

This corresponds to the global attribute resource symbol layout_alignBaseline.

Related Methods

android:layout_alignBottom

Makes the bottom edge of this view match the bottom edge of the given anchor view ID. Accommodates bottom margin.

Must be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

This corresponds to the global attribute resource symbol layout_alignBottom.

Related Methods

android:layout_alignEnd

Makes the end edge of this view match the end edge of the given anchor view ID. Accommodates end margin.

Must be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

This corresponds to the global attribute resource symbol layout_alignEnd.

Related Methods

android:layout_alignLeft

Makes the left edge of this view match the left edge of the given anchor view ID. Accommodates left margin.

Must be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

This corresponds to the global attribute resource symbol layout_alignLeft.

Related Methods

android:layout_alignParentBottom

If true, makes the bottom edge of this view match the bottom edge of the parent. Accommodates bottom margin.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol layout_alignParentBottom.

Related Methods

android:layout_alignParentEnd

If true, makes the end edge of this view match the end edge of the parent. Accommodates end margin.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol layout_alignParentEnd.

Related Methods

android:layout_alignParentLeft

If true, makes the left edge of this view match the left edge of the parent. Accommodates left margin.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol layout_alignParentLeft.

Related Methods

android:layout_alignParentRight

If true, makes the right edge of this view match the right edge of the parent. Accommodates right margin.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol layout_alignParentRight.

Related Methods

android:layout_alignParentStart

If true, makes the start edge of this view match the start edge of the parent. Accommodates start margin.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol layout_alignParentStart.

Related Methods

android:layout_alignParentTop

If true, makes the top edge of this view match the top edge of the parent. Accommodates top margin.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol layout_alignParentTop.

Related Methods

android:layout_alignRight

Makes the right edge of this view match the right edge of the given anchor view ID. Accommodates right margin.

Must be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

This corresponds to the global attribute resource symbol layout_alignRight.

Related Methods

android:layout_alignStart

Makes the start edge of this view match the start edge of the given anchor view ID. Accommodates start margin.

Must be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

This corresponds to the global attribute resource symbol layout_alignStart.

Related Methods

android:layout_alignTop

Makes the top edge of this view match the top edge of the given anchor view ID. Accommodates top margin.

Must be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

This corresponds to the global attribute resource symbol layout_alignTop.

Related Methods

android:layout_alignWithParentIfMissing

If set to true, the parent will be used as the anchor when the anchor cannot be be found for layout_toLeftOf, layout_toRightOf, etc.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol layout_alignWithParentIfMissing.

Related Methods

android:layout_below

Positions the top edge of this view below the given anchor view ID. Accommodates top margin of this view and bottom margin of anchor view.

Must be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

This corresponds to the global attribute resource symbol layout_below.

Related Methods

android:layout_centerHorizontal

If true, centers this child horizontally within its parent.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol layout_centerHorizontal.

Related Methods

android:layout_centerInParent

If true, centers this child horizontally and vertically within its parent.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol layout_centerInParent.

Related Methods

android:layout_centerVertical

If true, centers this child vertically within its parent.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol layout_centerVertical.

Related Methods

android:layout_toEndOf

Positions the start edge of this view to the end of the given anchor view ID. Accommodates start margin of this view and end margin of anchor view.

Must be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

This corresponds to the global attribute resource symbol layout_toEndOf.

Related Methods

android:layout_toLeftOf

Positions the right edge of this view to the left of the given anchor view ID. Accommodates right margin of this view and left margin of anchor view.

Must be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

This corresponds to the global attribute resource symbol layout_toLeftOf.

Related Methods

android:layout_toRightOf

Positions the left edge of this view to the right of the given anchor view ID. Accommodates left margin of this view and right margin of anchor view.

Must be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

This corresponds to the global attribute resource symbol layout_toRightOf.

Related Methods

android:layout_toStartOf

Positions the end edge of this view to the start of the given anchor view ID. Accommodates end margin of this view and start margin of anchor view.

Must be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

This corresponds to the global attribute resource symbol layout_toStartOf.

Related Methods

Fields

public boolean alignWithParent

Added in API level 1

When true, uses the parent as the anchor if the anchor doesn't exist or if the anchor's visibility is GONE.

Public Constructors

public RelativeLayout.LayoutParams (Context c, AttributeSet attrs)

Added in API level 1

public RelativeLayout.LayoutParams (int w, int h)

Added in API level 1

public RelativeLayout.LayoutParams (ViewGroup.LayoutParams source)

Added in API level 1

public RelativeLayout.LayoutParams (ViewGroup.MarginLayoutParams source)

Added in API level 1

public RelativeLayout.LayoutParams (RelativeLayout.LayoutParams source)

Added in API level 19

Copy constructor. Clones the width, height, margin values, and rules of the source.

Parameters
source The layout params to copy from.

Public Methods

public void addRule (int verb)

Added in API level 1

Adds a layout rule to be interpreted by the RelativeLayout. This method should only be used for constraints that don't refer to another sibling (e.g., CENTER_IN_PARENT) or take a boolean value (TRUE for true or 0 for false). To specify a verb that takes a subject, use addRule(int, int) instead.

Parameters
verb One of the verbs defined by RelativeLayout, such as ALIGN_WITH_PARENT_LEFT.

public void addRule (int verb, int anchor)

Added in API level 1

Adds a layout rule to be interpreted by the RelativeLayout. Use this for verbs that take a target, such as a sibling (ALIGN_RIGHT) or a boolean value (VISIBLE).

Parameters
verb One of the verbs defined by RelativeLayout, such as ALIGN_WITH_PARENT_LEFT.
anchor The id of another view to use as an anchor, or a boolean value(represented as TRUE) for true or 0 for false). For verbs that don't refer to another sibling (for example, ALIGN_WITH_PARENT_BOTTOM) just use -1.
See Also

public String debug (String output)

Added in API level 1

Returns a String representation of this set of layout parameters.

Parameters
output the String to prepend to the internal representation
Returns
  • a String with the following format: output + "ViewGroup.LayoutParams={ width=WIDTH, height=HEIGHT }"

public int[] getRules ()

Added in API level 1

Retrieves a complete list of all supported rules, where the index is the rule verb, and the element value is the value specified, or "false" if it was never set. There will be no resolution of relative rules done.

Returns
  • the supported rules

public void removeRule (int verb)

Added in API level 17

Removes a layout rule to be interpreted by the RelativeLayout.

Parameters
verb One of the verbs defined by RelativeLayout, such as ALIGN_WITH_PARENT_LEFT.

public void resolveLayoutDirection (int layoutDirection)

Added in API level 17

This will be called by requestLayout(). Left and Right margins may be overridden depending on layout direction.

Parameters
layoutDirection the direction of the layout LAYOUT_DIRECTION_LTR LAYOUT_DIRECTION_RTL