Stay organized with collections
Save and categorize content based on your preferences.
Guideline
public
class
Guideline
extends View
java.lang.Object
|
↳ |
View
|
|
↳ |
android.support.constraint.Guideline
|
Utility class representing a Guideline helper object for ConstraintLayout
.
Helper objects are not displayed on device (they are marked as View.GONE
) and are only used
for layout purposes. They only work within a ConstraintLayout
.
A Guideline can be either horizontal or vertical:
- Vertical Guidelines have a width of zero and the height of their
ConstraintLayout
parent
- Horizontal Guidelines have a height of zero and the width of their
ConstraintLayout
parent
Positioning a Guideline is possible in three different ways:
- specifying a fixed distance from the left or the top of a layout (
layout_constraintGuide_begin
)
- specifying a fixed distance from the right or the bottom of a layout (
layout_constraintGuide_end
)
- specifying a percentage of the width or the height of a layout (
layout_constraintGuide_percent
)
Widgets can then be constrained to a Guideline, allowing multiple widgets to be positioned easily from
one Guideline, or allowing reactive layout behavior by using percent positioning.
See the list of attributes in ConstraintLayout.LayoutParams
to set a Guideline
in XML, as well as the corresponding ConstraintSet.setGuidelineBegin(int, int)
, ConstraintSet.setGuidelineEnd(int, int)
and ConstraintSet.setGuidelinePercent(int, float)
functions in ConstraintSet
.
Example of a Button
constrained to a vertical Guideline
:
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.constraint.Guideline
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/guideline"
app:layout_constraintGuide_begin="100dp"
android:orientation="vertical"/>
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button"
app:layout_constraintLeft_toLeftOf="@+id/guideline"
android:layout_marginTop="16dp"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
Summary
Public constructors |
Guideline(Context context)
|
Guideline(Context context, AttributeSet attrs)
|
Guideline(Context context, AttributeSet attrs, int defStyleAttr)
|
Guideline(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)
|
Inherited methods |
From class
java.lang.Object
Object
|
clone()
|
boolean
|
equals(Object arg0)
|
void
|
finalize()
|
final
Class<?>
|
getClass()
|
int
|
hashCode()
|
final
void
|
notify()
|
final
void
|
notifyAll()
|
String
|
toString()
|
final
void
|
wait(long arg0, int arg1)
|
final
void
|
wait(long arg0)
|
final
void
|
wait()
|
|
Public constructors
Guideline
public Guideline (Context context)
Parameters |
context |
Context |
Guideline
public Guideline (Context context,
AttributeSet attrs)
Parameters |
context |
Context |
attrs |
AttributeSet |
Guideline
public Guideline (Context context,
AttributeSet attrs,
int defStyleAttr)
Parameters |
context |
Context |
attrs |
AttributeSet |
defStyleAttr |
int |
Guideline
public Guideline (Context context,
AttributeSet attrs,
int defStyleAttr,
int defStyleRes)
Parameters |
context |
Context |
attrs |
AttributeSet |
defStyleAttr |
int |
defStyleRes |
int |
Public methods
setGuidelineBegin
public void setGuidelineBegin (int margin)
Set the guideline's distance from the top or left edge.
Parameters |
margin |
int : the distance to the top or left edge
|
setGuidelineEnd
public void setGuidelineEnd (int margin)
Set a guideline's distance to end.
Parameters |
margin |
int : the margin to the right or bottom side of container
|
setGuidelinePercent
public void setGuidelinePercent (float ratio)
Set a Guideline's percent.
Parameters |
ratio |
float : the ratio between the gap on the left and right 0.0 is top/left 0.5 is middle
|
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[null,null,["Last updated 2025-02-10 UTC."],[],[],null,["# Guideline\n\nSummary: [Ctors](#pubctors) \\| [Methods](#pubmethods) \\| [Inherited Methods](#inhmethods) \n\nGuideline\n=========\n\n| This package is part of the Android [support library](/topic/libraries/support-library) which is no longer maintained. The Constraint Layout support library has been superseded by the [AndroidX Constraint\n| Layout library](/reference/androidx/constraintlayout/classes), which is part of [Jetpack](/jetpack). The `Guideline` class has been superseded by [`androidx.constraintlayout.widget/Guideline`](/reference/androidx/constraintlayout/widget/Guideline). We recommend using the AndroidX libraries in all new projects. You should also consider [migrating](/jetpack/androidx/migrate) existing projects to AndroidX.\n\n\n`\npublic\n\n\nclass\nGuideline\n`\n\n\n`\n\n\n`\n\n`\n\nextends View\n\n\n`\n\n`\n\n\n`\n\n|---|---|--------------------------------------|\n| java.lang.Object |||\n| ↳ | View ||\n| | ↳ | android.support.constraint.Guideline |\n\n\u003cbr /\u003e\n\n*** ** * ** ***\n\nUtility class representing a Guideline helper object for [ConstraintLayout](/reference/android/support/constraint/ConstraintLayout).\nHelper objects are not displayed on device (they are marked as `View.GONE`) and are only used\nfor layout purposes. They only work within a [ConstraintLayout](/reference/android/support/constraint/ConstraintLayout).\n\n\nA Guideline can be either horizontal or vertical:\n\n- Vertical Guidelines have a width of zero and the height of their [ConstraintLayout](/reference/android/support/constraint/ConstraintLayout) parent\n- Horizontal Guidelines have a height of zero and the width of their [ConstraintLayout](/reference/android/support/constraint/ConstraintLayout) parent\n\n\nPositioning a Guideline is possible in three different ways:\n\n- specifying a fixed distance from the left or the top of a layout (`layout_constraintGuide_begin`)\n- specifying a fixed distance from the right or the bottom of a layout (`layout_constraintGuide_end`)\n- specifying a percentage of the width or the height of a layout (`layout_constraintGuide_percent`)\n\n\nWidgets can then be constrained to a Guideline, allowing multiple widgets to be positioned easily from\none Guideline, or allowing reactive layout behavior by using percent positioning.\n\n\nSee the list of attributes in [ConstraintLayout.LayoutParams](/reference/android/support/constraint/ConstraintLayout.LayoutParams) to set a Guideline\nin XML, as well as the corresponding [ConstraintSet.setGuidelineBegin(int, int)](/reference/android/support/constraint/ConstraintSet#setGuidelineBegin(int,%20int)), [ConstraintSet.setGuidelineEnd(int, int)](/reference/android/support/constraint/ConstraintSet#setGuidelineEnd(int,%20int))\nand [ConstraintSet.setGuidelinePercent(int, float)](/reference/android/support/constraint/ConstraintSet#setGuidelinePercent(int,%20float)) functions in [ConstraintSet](/reference/android/support/constraint/ConstraintSet).\n\n\nExample of a `Button` constrained to a vertical `Guideline`: \n\n```\n\u003candroid.support.constraint.ConstraintLayout\n xmlns:android=\"http://schemas.android.com/apk/res/android\"\n xmlns:app=\"http://schemas.android.com/apk/res-auto\"\n xmlns:tools=\"http://schemas.android.com/tools\"\n android:layout_width=\"match_parent\"\n android:layout_height=\"match_parent\"\u003e\n\n \u003candroid.support.constraint.Guideline\n android:layout_width=\"wrap_content\"\n android:layout_height=\"wrap_content\"\n android:id=\"@+id/guideline\"\n app:layout_constraintGuide_begin=\"100dp\"\n android:orientation=\"vertical\"/\u003e\n\n \u003cButton\n android:text=\"Button\"\n android:layout_width=\"wrap_content\"\n android:layout_height=\"wrap_content\"\n android:id=\"@+id/button\"\n app:layout_constraintLeft_toLeftOf=\"@+id/guideline\"\n android:layout_marginTop=\"16dp\"\n app:layout_constraintTop_toTopOf=\"parent\" /\u003e\n\n\u003c/android.support.constraint.ConstraintLayout\u003e\n```\n\n\u003cbr /\u003e\n\nSummary\n-------\n\n| ### Public constructors ||\n|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|\n| ` `[Guideline](/reference/android/support/constraint/Guideline#Guideline(Context))`(Context context) ` |\n| ` `[Guideline](/reference/android/support/constraint/Guideline#Guideline(Context,%20AttributeSet))`(Context context, AttributeSet attrs) ` |\n| ` `[Guideline](/reference/android/support/constraint/Guideline#Guideline(Context,%20AttributeSet,%20int))`(Context context, AttributeSet attrs, int defStyleAttr) ` |\n| ` `[Guideline](/reference/android/support/constraint/Guideline#Guideline(Context,%20AttributeSet,%20int,%20int))`(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) ` |\n\n| ### Public methods ||\n|---------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ` void` | ` `[setGuidelineBegin](/reference/android/support/constraint/Guideline#setGuidelineBegin(int))`(int margin) ` Set the guideline's distance from the top or left edge. |\n| ` void` | ` `[setGuidelineEnd](/reference/android/support/constraint/Guideline#setGuidelineEnd(int))`(int margin) ` Set a guideline's distance to end. |\n| ` void` | ` `[setGuidelinePercent](/reference/android/support/constraint/Guideline#setGuidelinePercent(float))`(float ratio) ` Set a Guideline's percent. |\n\n| ### Inherited methods |\n|-----------------------|---|\n| From class ` java.lang.Object ` |-------------------|-------------------------------| | ` Object` | ` clone() ` | | ` boolean` | ` equals(Object arg0) ` | | ` void` | ` finalize() ` | | ` final Class\u003c?\u003e` | ` getClass() ` | | ` int` | ` hashCode() ` | | ` final void` | ` notify() ` | | ` final void` | ` notifyAll() ` | | ` String` | ` toString() ` | | ` final void` | ` wait(long arg0, int arg1) ` | | ` final void` | ` wait(long arg0) ` | | ` final void` | ` wait() ` | ||\n\nPublic constructors\n-------------------\n\n### Guideline\n\n```\npublic Guideline (Context context)\n```\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Parameters ||\n|-----------|------------------|\n| `context` | `Context` \u003cbr /\u003e |\n\n### Guideline\n\n```\npublic Guideline (Context context, \n AttributeSet attrs)\n```\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Parameters ||\n|-----------|-----------------------|\n| `context` | `Context` \u003cbr /\u003e |\n| `attrs` | `AttributeSet` \u003cbr /\u003e |\n\n### Guideline\n\n```\npublic Guideline (Context context, \n AttributeSet attrs, \n int defStyleAttr)\n```\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Parameters ||\n|----------------|-----------------------|\n| `context` | `Context` \u003cbr /\u003e |\n| `attrs` | `AttributeSet` \u003cbr /\u003e |\n| `defStyleAttr` | `int` \u003cbr /\u003e |\n\n### Guideline\n\n```\npublic Guideline (Context context, \n AttributeSet attrs, \n int defStyleAttr, \n int defStyleRes)\n```\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Parameters ||\n|----------------|-----------------------|\n| `context` | `Context` \u003cbr /\u003e |\n| `attrs` | `AttributeSet` \u003cbr /\u003e |\n| `defStyleAttr` | `int` \u003cbr /\u003e |\n| `defStyleRes` | `int` \u003cbr /\u003e |\n\nPublic methods\n--------------\n\n### setGuidelineBegin\n\n```\npublic void setGuidelineBegin (int margin)\n```\n\nSet the guideline's distance from the top or left edge.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|----------|----------------------------------------------------|\n| `margin` | `int`: the distance to the top or left edge \u003cbr /\u003e |\n\n### setGuidelineEnd\n\n```\npublic void setGuidelineEnd (int margin)\n```\n\nSet a guideline's distance to end.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|----------|-------------------------------------------------------------------|\n| `margin` | `int`: the margin to the right or bottom side of container \u003cbr /\u003e |\n\n### setGuidelinePercent\n\n```\npublic void setGuidelinePercent (float ratio)\n```\n\nSet a Guideline's percent.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|---------|-----------------------------------------------------------------------------------------------|\n| `ratio` | `float`: the ratio between the gap on the left and right 0.0 is top/left 0.5 is middle \u003cbr /\u003e |"]]