Added in API level 1

LinearLayout


open class LinearLayout : ViewGroup
kotlin.Any
   ↳ android.view.View
   ↳ android.view.ViewGroup
   ↳ android.widget.LinearLayout

A layout that arranges other views either horizontally in a single column or vertically in a single row.

The following snippet shows how to include a linear layout in your layout XML file:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:orientation="horizontal"
    android:gravity="center">
 
    <!-- Include other widget or layout tags here. These are considered
            "child views" or "children" of the linear layout -->
 
  </LinearLayout>

Set android:orientation to specify whether child views are displayed in a row or column.

To control how linear layout aligns all the views it contains, set a value for android:gravity. For example, the snippet above sets android:gravity to "center". The value you set affects both horizontal and vertical alignment of all child views within the single row or column.

You can set android:layout_weight on individual child views to specify how linear layout divides remaining space amongst the views it contains. See the Linear Layout guide for an example.

See LinearLayout.LayoutParams to learn about other attributes you can set on a child view to affect its position and size in the containing linear layout.

Summary

Nested classes
open

Per-child layout information associated with ViewLinearLayout.

XML attributes
android:baselineAligned When set to false, prevents the layout from aligning its children's baselines.
android:baselineAlignedChildIndex When a linear layout is part of another layout that is baseline aligned, it can specify which of its children to baseline align to (that is, which child TextView).
android:gravity Specifies how an object should position its content, on both the X and Y axes, within its own bounds.
android:measureWithLargestChild When set to true, all children with a weight will be considered having the minimum size of the largest child.
android:orientation Should the layout be a column or a row? Use "horizontal" for a row, "vertical" for a column.
android:weightSum Defines the maximum weight sum.
Inherited XML attributes
Constants
static Int

static Int

Show a divider at the beginning of the group.

static Int

Show a divider at the end of the group.

static Int

Show dividers between each item in the group.

static Int

Don't show any dividers.

static Int

Inherited constants
Public constructors
LinearLayout(context: Context!)

LinearLayout(context: Context!, attrs: AttributeSet?)

LinearLayout(context: Context!, attrs: AttributeSet?, defStyleAttr: Int)

LinearLayout(context: Context!, attrs: AttributeSet!, defStyleAttr: Int, defStyleRes: Int)

Public methods
open LinearLayout.LayoutParams!

open CharSequence!

open Int

open Int

open Drawable!

open Int

Get the padding size used to inset dividers in pixels

open Int

Returns the current gravity.

open Int

Returns the current orientation.

open Int

open Float

Returns the desired weights sum.

open Boolean

Indicates whether widgets contained within this layout are aligned on their baseline or not.

open Boolean

When true, all children with a weight will be considered having the minimum size of the largest child.

open Unit
onRtlPropertiesChanged(layoutDirection: Int)

Called when any RTL property (layout direction or text direction or text alignment) has been changed.

open Unit
setBaselineAligned(baselineAligned: Boolean)

Defines whether widgets contained in this layout are baseline-aligned or not.

open Unit

open Unit

Set a drawable to be used as a divider between items.

open Unit

Set padding displayed on both ends of dividers.

open Unit
setGravity(gravity: Int)

Describes how the child views are positioned.

open Unit
setHorizontalGravity(horizontalGravity: Int)

open Unit

When set to true, all children with a weight will be considered having the minimum size of the largest child.

open Unit
setOrientation(orientation: Int)

Should the layout be a column or a row.

open Unit
setShowDividers(showDividers: Int)

Set how dividers should be shown between items in this layout

open Unit
setVerticalGravity(verticalGravity: Int)

open Unit
setWeightSum(weightSum: Float)

Defines the desired weights sum.

open Boolean

Protected methods
open Boolean

open LinearLayout.LayoutParams!

Returns a set of layout parameters with a width of android.view.ViewGroup.LayoutParams#MATCH_PARENT and a height of android.view.ViewGroup.LayoutParams#WRAP_CONTENT when the layout's orientation is VERTICAL.

open LinearLayout.LayoutParams!

open Unit
onDraw(canvas: Canvas)

open Unit
onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int)

open Unit
onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int)

Inherited functions