LinearLayoutCompat

open class LinearLayoutCompat : ViewGroup
kotlin.Any
   ↳ android.view.View
   ↳ android.view.ViewGroup
   ↳ androidx.appcompat.widget.LinearLayoutCompat

A Layout that arranges its children in a single column or a single row. The direction of the row can be set by calling setOrientation(). You can also specify gravity, which specifies the alignment of all the child elements by calling setGravity() or specify that specific children grow to fill up any remaining space in the layout by setting the weight member of LinearLayoutCompat.LayoutParams. The default orientation is horizontal.

See the Linear Layout guide.

Also see LinearLayoutCompat.LayoutParams for layout attributes

Summary

Nested classes
open

Per-child layout information associated with ViewLinearLayout.

Constants
static Int

static Int

static Int

Don't show any dividers.

static Int

Show a divider at the beginning of the group.

static Int

Show dividers between each item in the group.

static Int

Show a divider at the end of the group.

Public constructors
<init>(context: Context!)

<init>(context: Context!, attrs: AttributeSet!)

<init>(context: Context!, attrs: AttributeSet!, defStyleAttr: Int)

Public methods
open Unit
setShowDividers(showDividers: Int)

Set how dividers should be shown between items in this layout

open Unit

Set padding displayed on both ends of dividers.

open Int

open Int

open Unit

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

open Boolean

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

open Unit
setGravity(gravity: Int)

Describes how the child views are positioned.

open 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

open Unit
setWeightSum(weightSum: Float)

Defines the desired weights sum.

open Boolean

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

open LinearLayoutCompat.LayoutParams!

open Unit
setVerticalGravity(verticalGravity: Int)

open Boolean

open Unit

open Float

Returns the desired weights sum.

open Unit
setOrientation(orientation: Int)

Should the layout be a column or a row.

open Int

Returns the current gravity.

open Int

Get the padding size used to inset dividers in pixels

open Drawable!

open Unit
setHorizontalGravity(horizontalGravity: Int)

open Unit

open Int

Returns the current orientation.

open Unit
setBaselineAligned(baselineAligned: Boolean)

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

Protected methods
open Boolean

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

open LinearLayoutCompat.LayoutParams!

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

open LinearLayoutCompat.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 Unit
onDraw(canvas: Canvas!)

Constants

HORIZONTAL

static val HORIZONTAL: Int
Value: 0

VERTICAL

static val VERTICAL: Int
Value: 1

SHOW_DIVIDER_NONE

static val SHOW_DIVIDER_NONE: Int

Don't show any dividers.

Value: 0

SHOW_DIVIDER_BEGINNING

static val SHOW_DIVIDER_BEGINNING: Int

Show a divider at the beginning of the group.

Value: 1

SHOW_DIVIDER_MIDDLE

static val SHOW_DIVIDER_MIDDLE: Int

Show dividers between each item in the group.

Value: 2

SHOW_DIVIDER_END

static val SHOW_DIVIDER_END: Int

Show a divider at the end of the group.

Value: 4

Public constructors

<init>

LinearLayoutCompat(context: Context!)

<init>

LinearLayoutCompat(context: Context!, attrs: AttributeSet!)

<init>

LinearLayoutCompat(context: Context!, attrs: AttributeSet!, defStyleAttr: Int)

Public methods

setShowDividers

open fun setShowDividers(showDividers: Int): Unit

Set how dividers should be shown between items in this layout

Parameters
showDividers Int: One or more of SHOW_DIVIDER_BEGINNING, SHOW_DIVIDER_MIDDLE, or SHOW_DIVIDER_END, or SHOW_DIVIDER_NONE to show no dividers.

setDividerPadding

open fun setDividerPadding(padding: Int): Unit

Set padding displayed on both ends of dividers.

Parameters
padding Int: Padding value in pixels that will be applied to each end

getBaseline

open fun getBaseline(): Int

getShowDividers

open fun getShowDividers(): Int
Return
Int: A flag set indicating how dividers should be shown around items.

setDividerDrawable

open fun setDividerDrawable(divider: Drawable!): Unit

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

Parameters
divider Drawable!: Drawable that will divide each item.

isBaselineAligned

open fun isBaselineAligned(): Boolean

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

Return
Boolean: true when widgets are baseline-aligned, false otherwise

setGravity

open fun setGravity(gravity: Int): Unit

Describes how the child views are positioned. Defaults to GRAVITY_TOP. If this layout has a VERTICAL orientation, this controls where all the child views are placed if there is extra vertical space. If this layout has a HORIZONTAL orientation, this controls the alignment of the children.

Parameters
gravity Int: See android.view.Gravity

getBaselineAlignedChildIndex

open fun getBaselineAlignedChildIndex(): Int
Return
Int: The index of the child that will be used if this layout is part of a larger layout that is baseline aligned, or -1 if none has been set.

setMeasureWithLargestChildEnabled

open fun setMeasureWithLargestChildEnabled(enabled: Boolean): Unit

When set to true, all children with a weight will be considered having the minimum size of the largest child. If false, all children are measured normally. Disabled by default.

Parameters
enabled Boolean: True to measure children with a weight using the minimum size of the largest child, false otherwise.

onInitializeAccessibilityEvent

open fun onInitializeAccessibilityEvent(event: AccessibilityEvent!): Unit

setWeightSum

open fun setWeightSum(weightSum: Float): Unit

Defines the desired weights sum. If unspecified the weights sum is computed at layout time by adding the layout_weight of each child. This can be used for instance to give a single child 50% of the total available space by giving it a layout_weight of 0.5 and setting the weightSum to 1.0.

Parameters
weightSum Float: a number greater than 0.0f, or a number lower than or equals to 0.0f if the weight sum should be computed from the children's layout_weight

isMeasureWithLargestChildEnabled

open fun isMeasureWithLargestChildEnabled(): Boolean

When true, all children with a weight will be considered having the minimum size of the largest child. If false, all children are measured normally.

Return
Boolean: True to measure children with a weight using the minimum size of the largest child, false otherwise.

generateLayoutParams

open fun generateLayoutParams(attrs: AttributeSet!): LinearLayoutCompat.LayoutParams!

setVerticalGravity

open fun setVerticalGravity(verticalGravity: Int): Unit

shouldDelayChildPressedState

open fun shouldDelayChildPressedState(): Boolean

onInitializeAccessibilityNodeInfo

open fun onInitializeAccessibilityNodeInfo(info: AccessibilityNodeInfo!): Unit

getWeightSum

open fun getWeightSum(): Float

Returns the desired weights sum.

Return
Float: A number greater than 0.0f if the weight sum is defined, or a number lower than or equals to 0.0f if not weight sum is to be used.

setOrientation

open fun setOrientation(orientation: Int): Unit

Should the layout be a column or a row.

Parameters
orientation Int: Pass HORIZONTAL or VERTICAL. Default value is HORIZONTAL.

getGravity

open fun getGravity(): Int

Returns the current gravity. See android.view.Gravity

Return
Int: the current gravity.

See Also

getDividerPadding

open fun getDividerPadding(): Int

Get the padding size used to inset dividers in pixels

getDividerDrawable

open fun getDividerDrawable(): Drawable!
Return
Drawable!: the divider Drawable that will divide each item.

setHorizontalGravity

open fun setHorizontalGravity(horizontalGravity: Int): Unit

setBaselineAlignedChildIndex

open fun setBaselineAlignedChildIndex(i: Int): Unit
Parameters
i Int: The index of the child that will be used if this layout is part of a larger layout that is baseline aligned.

getOrientation

open fun getOrientation(): Int

Returns the current orientation.

Return
Int: either HORIZONTAL or VERTICAL

setBaselineAligned

open fun setBaselineAligned(baselineAligned: Boolean): Unit

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

Parameters
baselineAligned Boolean: true to align widgets on their baseline, false otherwise

Protected methods

checkLayoutParams

protected open fun checkLayoutParams(p: LayoutParams!): Boolean

onLayout

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

generateLayoutParams

protected open fun generateLayoutParams(p: LayoutParams!): LinearLayoutCompat.LayoutParams!

onMeasure

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

generateDefaultLayoutParams

protected open fun generateDefaultLayoutParams(): LinearLayoutCompat.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. When the orientation is HORIZONTAL, the width is set to LayoutParams#WRAP_CONTENT and the height to LayoutParams#WRAP_CONTENT.

onDraw

protected open fun onDraw(canvas: Canvas!): Unit