Android APIs
public class

LinearLayoutCompat

extends ViewGroup
java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ android.support.v7.widget.LinearLayoutCompat
Known Direct Subclasses

Class Overview

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
class LinearLayoutCompat.LayoutParams Per-child layout information associated with ViewLinearLayout. 
[Expand]
Inherited XML Attributes
From class android.view.ViewGroup
From class android.view.View
Constants
int HORIZONTAL
int SHOW_DIVIDER_BEGINNING Show a divider at the beginning of the group.
int SHOW_DIVIDER_END Show a divider at the end of the group.
int SHOW_DIVIDER_MIDDLE Show dividers between each item in the group.
int SHOW_DIVIDER_NONE Don't show any dividers.
int VERTICAL
[Expand]
Inherited Constants
From class android.view.ViewGroup
From class android.view.View
[Expand]
Inherited Fields
From class android.view.View
Public Constructors
LinearLayoutCompat(Context context)
LinearLayoutCompat(Context context, AttributeSet attrs)
LinearLayoutCompat(Context context, AttributeSet attrs, int defStyleAttr)
Public Methods
LinearLayoutCompat.LayoutParams generateLayoutParams(AttributeSet attrs)
Returns a new set of layout parameters based on the supplied attributes set.
int getBaseline()

Return the offset of the widget's text baseline from the widget's top boundary.

int getBaselineAlignedChildIndex()
Drawable getDividerDrawable()
int getDividerPadding()
Get the padding size used to inset dividers in pixels
int getOrientation()
Returns the current orientation.
int getShowDividers()
float getWeightSum()
Returns the desired weights sum.
boolean isBaselineAligned()

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

boolean isMeasureWithLargestChildEnabled()
When true, all children with a weight will be considered having the minimum size of the largest child.
void onInitializeAccessibilityEvent(AccessibilityEvent event)
Initializes an AccessibilityEvent with information about this View which is the event source.
void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info)
Initializes an AccessibilityNodeInfo with information about this view.
void setBaselineAligned(boolean baselineAligned)

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

void setBaselineAlignedChildIndex(int i)
void setDividerDrawable(Drawable divider)
Set a drawable to be used as a divider between items.
void setDividerPadding(int padding)
Set padding displayed on both ends of dividers.
void setGravity(int gravity)
Describes how the child views are positioned.
void setHorizontalGravity(int horizontalGravity)
void setMeasureWithLargestChildEnabled(boolean enabled)
When set to true, all children with a weight will be considered having the minimum size of the largest child.
void setOrientation(int orientation)
Should the layout be a column or a row.
void setShowDividers(int showDividers)
Set how dividers should be shown between items in this layout
void setVerticalGravity(int verticalGravity)
void setWeightSum(float weightSum)
Defines the desired weights sum.
boolean shouldDelayChildPressedState()
Return true if the pressed state should be delayed for children or descendants of this ViewGroup.
Protected Methods
boolean checkLayoutParams(ViewGroup.LayoutParams p)
LinearLayoutCompat.LayoutParams generateDefaultLayoutParams()
Returns a set of layout parameters with a width of MATCH_PARENT and a height of WRAP_CONTENT when the layout's orientation is VERTICAL.
LinearLayoutCompat.LayoutParams generateLayoutParams(ViewGroup.LayoutParams p)
Returns a safe set of layout parameters based on the supplied layout params.
void onDraw(Canvas canvas)
Implement this to do your drawing.
void onLayout(boolean changed, int l, int t, int r, int b)
Called from layout when this view should assign a size and position to each of its children.
void onMeasure(int widthMeasureSpec, int heightMeasureSpec)

Measure the view and its content to determine the measured width and the measured height.

[Expand]
Inherited Methods
From class android.view.ViewGroup
From class android.view.View
From class java.lang.Object
From interface android.view.ViewParent
From interface android.view.ViewManager
From interface android.graphics.drawable.Drawable.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.accessibility.AccessibilityEventSource

Constants

public static final int HORIZONTAL

Constant Value: 0 (0x00000000)

public static final int SHOW_DIVIDER_BEGINNING

Show a divider at the beginning of the group.

Constant Value: 1 (0x00000001)

public static final int SHOW_DIVIDER_END

Show a divider at the end of the group.

Constant Value: 4 (0x00000004)

public static final int SHOW_DIVIDER_MIDDLE

Show dividers between each item in the group.

Constant Value: 2 (0x00000002)

public static final int SHOW_DIVIDER_NONE

Don't show any dividers.

Constant Value: 0 (0x00000000)

public static final int VERTICAL

Constant Value: 1 (0x00000001)

Public Constructors

public LinearLayoutCompat (Context context)

public LinearLayoutCompat (Context context, AttributeSet attrs)

public LinearLayoutCompat (Context context, AttributeSet attrs, int defStyleAttr)

Public Methods

public LinearLayoutCompat.LayoutParams generateLayoutParams (AttributeSet attrs)

Returns a new set of layout parameters based on the supplied attributes set.

Parameters
attrs the attributes to build the layout parameters from
Returns

public int getBaseline ()

Return the offset of the widget's text baseline from the widget's top boundary. If this widget does not support baseline alignment, this method returns -1.

Returns
  • the offset of the baseline within the widget's bounds or -1 if baseline alignment is not supported

public int getBaselineAlignedChildIndex ()

Returns
  • 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.

public Drawable getDividerDrawable ()

Returns
  • the divider Drawable that will divide each item.

public int getDividerPadding ()

Get the padding size used to inset dividers in pixels

public int getOrientation ()

Returns the current orientation.

Returns

public int getShowDividers ()

Returns
  • A flag set indicating how dividers should be shown around items.

public float getWeightSum ()

Returns the desired weights sum.

Returns
  • 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.

public boolean isBaselineAligned ()

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

Returns
  • true when widgets are baseline-aligned, false otherwise

public boolean isMeasureWithLargestChildEnabled ()

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.

Returns
  • True to measure children with a weight using the minimum size of the largest child, false otherwise.

public void onInitializeAccessibilityEvent (AccessibilityEvent event)

Initializes an AccessibilityEvent with information about this View which is the event source. In other words, the source of an accessibility event is the view whose state change triggered firing the event.

Example: Setting the password property of an event in addition to properties set by the super implementation:

 public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
     super.onInitializeAccessibilityEvent(event);
     event.setPassword(true);
 }

If an View.AccessibilityDelegate has been specified via calling setAccessibilityDelegate(AccessibilityDelegate) its onInitializeAccessibilityEvent(View, AccessibilityEvent) is responsible for handling this call.

Note: Always call the super implementation before adding information to the event, in case the default implementation has basic information to add.

Parameters
event The event to initialize.

public void onInitializeAccessibilityNodeInfo (AccessibilityNodeInfo info)

Initializes an AccessibilityNodeInfo with information about this view. The base implementation sets:

Subclasses should override this method, call the super implementation, and set additional attributes.

If an View.AccessibilityDelegate has been specified via calling setAccessibilityDelegate(AccessibilityDelegate) its onInitializeAccessibilityNodeInfo(View, AccessibilityNodeInfo) is responsible for handling this call.

Parameters
info The instance to initialize.

public void setBaselineAligned (boolean baselineAligned)

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

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

public void setBaselineAlignedChildIndex (int i)

Parameters
i The index of the child that will be used if this layout is part of a larger layout that is baseline aligned.

public void setDividerDrawable (Drawable divider)

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

Parameters
divider Drawable that will divide each item.

public void setDividerPadding (int padding)

Set padding displayed on both ends of dividers.

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

public void setGravity (int gravity)

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 See Gravity

public void setHorizontalGravity (int horizontalGravity)

public void setMeasureWithLargestChildEnabled (boolean enabled)

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 True to measure children with a weight using the minimum size of the largest child, false otherwise.

public void setOrientation (int orientation)

Should the layout be a column or a row.

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

public void setShowDividers (int showDividers)

Set how dividers should be shown between items in this layout

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

public void setVerticalGravity (int verticalGravity)

public void setWeightSum (float weightSum)

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 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

public boolean shouldDelayChildPressedState ()

Return true if the pressed state should be delayed for children or descendants of this ViewGroup. Generally, this should be done for containers that can scroll, such as a List. This prevents the pressed state from appearing when the user is actually trying to scroll the content. The default implementation returns true for compatibility reasons. Subclasses that do not scroll should generally override this method and return false.

Protected Methods

protected boolean checkLayoutParams (ViewGroup.LayoutParams p)

protected LinearLayoutCompat.LayoutParams generateDefaultLayoutParams ()

Returns a set of layout parameters with a width of MATCH_PARENT and a height of WRAP_CONTENT when the layout's orientation is VERTICAL. When the orientation is HORIZONTAL, the width is set to WRAP_CONTENT and the height to WRAP_CONTENT.

Returns
  • a set of default layout parameters or null

protected LinearLayoutCompat.LayoutParams generateLayoutParams (ViewGroup.LayoutParams p)

Returns a safe set of layout parameters based on the supplied layout params. When a ViewGroup is passed a View whose layout params do not pass the test of checkLayoutParams(android.view.ViewGroup.LayoutParams), this method is invoked. This method should return a new set of layout params suitable for this ViewGroup, possibly by copying the appropriate attributes from the specified set of layout params.

Parameters
p The layout parameters to convert into a suitable set of layout parameters for this ViewGroup.
Returns

protected void onDraw (Canvas canvas)

Implement this to do your drawing.

Parameters
canvas the canvas on which the background will be drawn

protected void onLayout (boolean changed, int l, int t, int r, int b)

Called from layout when this view should assign a size and position to each of its children. Derived classes with children should override this method and call layout on each of their children.

Parameters
changed This is a new size or position for this view
l Left position, relative to parent
t Top position, relative to parent
r Right position, relative to parent
b Bottom position, relative to parent

protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec)

Measure the view and its content to determine the measured width and the measured height. This method is invoked by measure(int, int) and should be overriden by subclasses to provide accurate and efficient measurement of their contents.

CONTRACT: When overriding this method, you must call setMeasuredDimension(int, int) to store the measured width and height of this view. Failure to do so will trigger an IllegalStateException, thrown by measure(int, int). Calling the superclass' onMeasure(int, int) is a valid use.

The base class implementation of measure defaults to the background size, unless a larger size is allowed by the MeasureSpec. Subclasses should override onMeasure(int, int) to provide better measurements of their content.

If this method is overridden, it is the subclass's responsibility to make sure the measured height and width are at least the view's minimum height and width (getSuggestedMinimumHeight() and getSuggestedMinimumWidth()).

Parameters
widthMeasureSpec horizontal space requirements as imposed by the parent. The requirements are encoded with View.MeasureSpec.
heightMeasureSpec vertical space requirements as imposed by the parent. The requirements are encoded with View.MeasureSpec.