# Guideline

Summary:[Ctors](https://developer.android.com/reference/android/support/constraint/Guideline#pubctors)\|[Methods](https://developer.android.com/reference/android/support/constraint/Guideline#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/support/constraint/Guideline#inhmethods)  

# Guideline

| This package is part of the Android[support library](https://developer.android.com/topic/libraries/support-library)which is no longer maintained. The Constraint Layout support library has been superseded by the[AndroidX Constraint Layout library](https://developer.android.com/reference/androidx/constraintlayout/classes), which is part of[Jetpack](https://developer.android.com/jetpack). The`Guideline`class has been superseded by[`androidx.constraintlayout.widget/Guideline`](https://developer.android.com/reference/androidx/constraintlayout/widget/Guideline). We recommend using the AndroidX libraries in all new projects. You should also consider[migrating](https://developer.android.com/jetpack/androidx/migrate)existing projects to AndroidX.

`
public


class
Guideline
`  
`


``

extends View


``


`

|---|---|--------------------------------------|
| java.lang.Object                           |||
| ↳ | View                                    ||
|   | ↳ | android.support.constraint.Guideline |

<br />

*** ** * ** ***

Utility class representing a Guideline helper object for[ConstraintLayout](https://developer.android.com/reference/android/support/constraint/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](https://developer.android.com/reference/android/support/constraint/ConstraintLayout).

A Guideline can be either horizontal or vertical:

- Vertical Guidelines have a width of zero and the height of their[ConstraintLayout](https://developer.android.com/reference/android/support/constraint/ConstraintLayout)parent
- Horizontal Guidelines have a height of zero and the width of their[ConstraintLayout](https://developer.android.com/reference/android/support/constraint/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](https://developer.android.com/reference/android/support/constraint/ConstraintLayout.LayoutParams)to set a Guideline in XML, as well as the corresponding[ConstraintSet.setGuidelineBegin(int, int)](https://developer.android.com/reference/android/support/constraint/ConstraintSet#setGuidelineBegin(int,%20int)),[ConstraintSet.setGuidelineEnd(int, int)](https://developer.android.com/reference/android/support/constraint/ConstraintSet#setGuidelineEnd(int,%20int))and[ConstraintSet.setGuidelinePercent(int, float)](https://developer.android.com/reference/android/support/constraint/ConstraintSet#setGuidelinePercent(int,%20float))functions in[ConstraintSet](https://developer.android.com/reference/android/support/constraint/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>
```

<br />

## Summary

|                                                                                                   ### Public constructors                                                                                                   ||
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| ` `[Guideline](https://developer.android.com/reference/android/support/constraint/Guideline#Guideline(Context))`(Context context) `                                                                                      |
| ` `[Guideline](https://developer.android.com/reference/android/support/constraint/Guideline#Guideline(Context,%20AttributeSet))`(Context context, AttributeSet attrs) `                                                  |
| ` `[Guideline](https://developer.android.com/reference/android/support/constraint/Guideline#Guideline(Context,%20AttributeSet,%20int))`(Context context, AttributeSet attrs, int defStyleAttr) `                         |
| ` `[Guideline](https://developer.android.com/reference/android/support/constraint/Guideline#Guideline(Context,%20AttributeSet,%20int,%20int))`(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) ` |

|                                                                                             ### Public methods                                                                                              ||
|---------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` void` | ` `[setGuidelineBegin](https://developer.android.com/reference/android/support/constraint/Guideline#setGuidelineBegin(int))`(int margin) ` Set the guideline's distance from the top or left edge. |
| ` void` | ` `[setGuidelineEnd](https://developer.android.com/reference/android/support/constraint/Guideline#setGuidelineEnd(int))`(int margin) ` Set a guideline's distance to end.                          |
| ` void` | ` `[setGuidelinePercent](https://developer.android.com/reference/android/support/constraint/Guideline#setGuidelinePercent(float))`(float ratio) ` Set a Guideline's percent.                       |

| ### 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)
```

<br />

<br />

|         Parameters          ||
|-----------|------------------|
| `context` | `Context` <br /> |

### Guideline

```
public Guideline (Context context, 
                AttributeSet attrs)
```

<br />

<br />

|            Parameters            ||
|-----------|-----------------------|
| `context` | `Context` <br />      |
| `attrs`   | `AttributeSet` <br /> |

### Guideline

```
public Guideline (Context context, 
                AttributeSet attrs, 
                int defStyleAttr)
```

<br />

<br />

|              Parameters               ||
|----------------|-----------------------|
| `context`      | `Context` <br />      |
| `attrs`        | `AttributeSet` <br /> |
| `defStyleAttr` | `int` <br />          |

### Guideline

```
public Guideline (Context context, 
                AttributeSet attrs, 
                int defStyleAttr, 
                int defStyleRes)
```

<br />

<br />

|              Parameters               ||
|----------------|-----------------------|
| `context`      | `Context` <br />      |
| `attrs`        | `AttributeSet` <br /> |
| `defStyleAttr` | `int` <br />          |
| `defStyleRes`  | `int` <br />          |

## Public methods

### setGuidelineBegin

```
public void setGuidelineBegin (int margin)
```

Set the guideline's distance from the top or left edge.

<br />

|                          Parameters                          ||
|----------|----------------------------------------------------|
| `margin` | `int`: the distance to the top or left edge <br /> |

### setGuidelineEnd

```
public void setGuidelineEnd (int margin)
```

Set a guideline's distance to end.

<br />

|                                 Parameters                                  ||
|----------|-------------------------------------------------------------------|
| `margin` | `int`: the margin to the right or bottom side of container <br /> |

### setGuidelinePercent

```
public void setGuidelinePercent (float ratio)
```

Set a Guideline's percent.

<br />

|                                               Parameters                                               ||
|---------|-----------------------------------------------------------------------------------------------|
| `ratio` | `float`: the ratio between the gap on the left and right 0.0 is top/left 0.5 is middle <br /> |