LayoutParams
open class LayoutParams
kotlin.Any | |
↳ | android.view.ViewGroup.LayoutParams |
LayoutParams are used by views to tell their parents how they want to be laid out. See ViewGroup Layout Attributes
for a list of all child view attributes that this class supports.
The base LayoutParams class just describes how big the view wants to be for both width and height. For each dimension, it can specify one of:
- FILL_PARENT (renamed MATCH_PARENT in API Level 8 and higher), which means that the view wants to be as big as its parent (minus padding)
- WRAP_CONTENT, which means that the view wants to be just big enough to enclose its content (plus padding)
- an exact number
Summary
XML attributes | |
---|---|
android:layout_height |
Specifies the basic height of the view. |
android:layout_width |
Specifies the basic width of the view. |
Constants | |
---|---|
static Int |
Special value for the height or width requested by a View. |
static Int |
Special value for the height or width requested by a View. |
static Int |
Special value for the height or width requested by a View. |
Public constructors | |
---|---|
LayoutParams(c: Context!, attrs: AttributeSet!) Creates a new set of layout parameters. |
|
LayoutParams(source: ViewGroup.LayoutParams!) Copy constructor. |
|
LayoutParams(width: Int, height: Int) Creates a new set of layout parameters with the specified width and height. |
Public methods | |
---|---|
open Unit |
resolveLayoutDirection(layoutDirection: Int) Resolve layout parameters depending on the layout direction. |
Protected methods | |
---|---|
open Unit |
setBaseAttributes(a: TypedArray!, widthAttr: Int, heightAttr: Int) Extracts the layout parameters from the supplied attributes. |
Properties | |
---|---|
Int |
Information about how tall the view wants to be. |
LayoutAnimationController.AnimationParameters! |
Used to animate layouts. |
Int |
Information about how wide the view wants to be. |
XML attributes
android:layout_height
android:layout_height
May be a dimension value, which is a floating point number appended with a unit such as "14.5sp
". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), and mm (millimeters).
Must be one of the following constant values.
Constant | Value | Description |
---|---|---|
fill_parent | ffffffff | The view should be as big as its parent (minus padding). This constant is deprecated starting from API Level 8 and is replaced by match_parent . |
match_parent | ffffffff | The view should be as big as its parent (minus padding). Introduced in API Level 8. |
wrap_content | fffffffe | The view should be only big enough to enclose its content (plus padding). |
android:layout_width
android:layout_width
May be a dimension value, which is a floating point number appended with a unit such as "14.5sp
". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), and mm (millimeters).
Must be one of the following constant values.
Constant | Value | Description |
---|---|---|
fill_parent | ffffffff | The view should be as big as its parent (minus padding). This constant is deprecated starting from API Level 8 and is replaced by match_parent . |
match_parent | ffffffff | The view should be as big as its parent (minus padding). Introduced in API Level 8. |
wrap_content | fffffffe | The view should be only big enough to enclose its content (plus padding). |
Constants
FILL_PARENT
static valFILL_PARENT: Int
Deprecated: Deprecated in Java.
Special value for the height or width requested by a View. FILL_PARENT means that the view wants to be as big as its parent, minus the parent's padding, if any. This value is deprecated starting in API Level 8 and replaced by MATCH_PARENT
.
Value: -1
MATCH_PARENT
static val MATCH_PARENT: Int
Special value for the height or width requested by a View. MATCH_PARENT means that the view wants to be as big as its parent, minus the parent's padding, if any. Introduced in API Level 8.
Value: -1
WRAP_CONTENT
static val WRAP_CONTENT: Int
Special value for the height or width requested by a View. WRAP_CONTENT means that the view wants to be just large enough to fit its own internal content, taking its own padding into account.
Value: -2
Public constructors
LayoutParams
LayoutParams(
c: Context!,
attrs: AttributeSet!)
Creates a new set of layout parameters. The values are extracted from the supplied attributes set and context. The XML attributes mapped to this set of layout parameters are:
layout_width
: the width, either an exact value,WRAP_CONTENT
, orFILL_PARENT
(replaced byMATCH_PARENT
in API Level 8)layout_height
: the height, either an exact value,WRAP_CONTENT
, orFILL_PARENT
(replaced byMATCH_PARENT
in API Level 8)
Parameters | |
---|---|
c |
Context!: the application environment |
attrs |
AttributeSet!: the set of attributes from which to extract the layout parameters' values |
LayoutParams
LayoutParams(source: ViewGroup.LayoutParams!)
Copy constructor. Clones the width and height values of the source.
Parameters | |
---|---|
source |
ViewGroup.LayoutParams!: The layout params to copy from. |
LayoutParams
LayoutParams(
width: Int,
height: Int)
Creates a new set of layout parameters with the specified width and height.
Parameters | |
---|---|
width |
Int: the width, either WRAP_CONTENT , FILL_PARENT (replaced by MATCH_PARENT in API Level 8), or a fixed size in pixels |
height |
Int: the height, either WRAP_CONTENT , FILL_PARENT (replaced by MATCH_PARENT in API Level 8), or a fixed size in pixels |
Public methods
resolveLayoutDirection
open fun resolveLayoutDirection(layoutDirection: Int): Unit
Resolve layout parameters depending on the layout direction. Subclasses that care about layoutDirection changes should override this method. The default implementation does nothing.
Parameters | |
---|---|
layoutDirection |
Int: the direction of the layout View.LAYOUT_DIRECTION_LTR View.LAYOUT_DIRECTION_RTL |
Protected methods
setBaseAttributes
protected open fun setBaseAttributes(
a: TypedArray!,
widthAttr: Int,
heightAttr: Int
): Unit
Extracts the layout parameters from the supplied attributes.
Parameters | |
---|---|
a |
TypedArray!: the style attributes to extract the parameters from |
widthAttr |
Int: the identifier of the width attribute |
heightAttr |
Int: the identifier of the height attribute |
Properties
height
var height: Int
Information about how tall the view wants to be. Can be one of the constants FILL_PARENT (replaced by MATCH_PARENT in API Level 8) or WRAP_CONTENT, or an exact size.
layoutAnimationParameters
var layoutAnimationParameters: LayoutAnimationController.AnimationParameters!
Used to animate layouts.
width
var width: Int
Information about how wide the view wants to be. Can be one of the constants FILL_PARENT (replaced by MATCH_PARENT in API Level 8) or WRAP_CONTENT, or an exact size.