ViewGroup.MarginLayoutParams

Class Overview(类概述)

layouts 的每个子 layout 信息都支持 margins。参考 ViewGroup Margin Layout Attributes 列举了该类支持的所有子 view 的属性。

XML Attributes(XML 属性)

android:layout_marginBotton

在该 view 的底边指定一个特定的空间。这个空间是在 view 边界的外部。margin 值应该是正数。

必须是一个具体的值,一个浮点数字加一个单位如『14.5sp』。可选的单位有:px(pixels 象素),dp(density-independent pixels 密度独立象素),sp(scaled pixels based on perferred font size 基于优选字体大小的缩放像素『一般用于设置字体大小』),mm(millimeters 毫米)。

也可能是对包含该类型值的资源或主题属性的引用。

这相当于全局属性资源符号 layout_marginBottom。

相关的方法:

setMargins(int,int,int,int)

android:layout_marginEnd

在该 view 的结束的一边指定一个特定的空间。这个空间是在 view 边界的外部。margin 的值应该是正数。

必须是一个具体的值,一个浮点数字加一个单位如『14.5sp』。可选的单位有:px(pixels 象素),dp(density-independent pixels 密度独立象素),sp(scaled pixels based on perferred font size 基于优选字体大小的缩放像素『一般用于设置字体大小』),mm(millimeters 毫米)。

也可能是对包含该类型值的资源或主题属性的引用。

这相当于全局属性资源符号 layout_marginEnd。

相关的方法:

setMarginEnd(int)

android_marginLeft

在该 view 的左边指定一个特定的空间。这个空间是在 view 边界的外部。margin 的值应该是正数。

必须是一个具体的值,一个浮点数字加一个单位如『14.5sp』。可选的单位有:px(pixels 象素),dp(density-independent pixels 密度独立象素),sp(scaled pixels based on perferred font size 基于优选字体大小的缩放像素『一般用于设置字体大小』),mm(millimeters 毫米)。

也可能是对包含该类型值的资源或主题属性的引用。

这相当于全局属性资源符号 layout_marginLeft。

相关的方法:

setMargins(int,int,int,int)

android:layout_marginRight

在该 view 的右边指定一个特定的空间。这个空间是在 view 边界的外部。margin 的值应该是正数。

必须是一个具体的值,一个浮点数字加一个单位如『14.5sp』。可选的单位有:px(pixels 象素),dp(density-independent pixels 密度独立象素),sp(scaled pixels based on perferred font size 基于优选字体大小的缩放像素『一般用于设置字体大小』),mm(millimeters 毫米)。

也可能是对包含该类型值的资源或主题属性的引用。

这相当于全局属性资源符号 layout_marginRight。

相关的方法:

setMargins(int,int,int,int)

android:layout_marginStart

在该 view 的开始的一边指定一个特定的空间。这个空间是在 view 边界的外部。margin 的值应该是正数。

必须是一个具体的值,一个浮点数字加一个单位如『14.5sp』。可选的单位有:px(pixels 象素),dp(density-independent pixels 密度独立象素),sp(scaled pixels based on perferred font size 基于优选字体大小的缩放像素『一般用于设置字体大小』),mm(millimeters 毫米)。

也可能是对包含该类型值的资源或主题属性的引用。

这相当于全局属性资源符号 layout_marginStart。

相关的方法:

setMarginStart(int)

android:layout_marginTop

在该 view 的上边指定一个特定的空间。这个空间是在 view 边界的外部。margin 的值应该是正数。

必须是一个具体的值,一个浮点数字加一个单位如『14.5sp』。可选的单位有:px(pixels 象素),dp(density-independent pixels 密度独立象素),sp(scaled pixels based on perferred font size 基于优选字体大小的缩放像素『一般用于设置字体大小』),mm(millimeters 毫米)。

也可能是对包含该类型值的资源或主题属性的引用。

这相当于全局属性资源符号 layout_marginTop。

相关的方法:

setMargins(int,int,int,int)

Fields(字段)

public int bottomMargin

以象素为单位的下边距。margin 值应该是正数。调用 setLayoutParams(LayoutParamsp) 方法后为这个值重新分配一个新的值。

public int leftMargin

以象素为单位的左边距。margin 值应该是正数。调用 setLayoutParams(LayoutParamsp) 方法后为这个值重新分配一个新的值。

public int rightMargin

以象素为单位的右边距。margin 值应该是正数。调用 setLayoutParams(LayoutParamsp) 方法后为这个值重新分配一个新的值。

public int topMargin

以象素为单位的上边距。margin 值应该是正数。调用 setLayoutParams(LayoutParamsp) 方法后为这个值重新分配一个新的值。

Public Constructors(公共构造方法)

public ViewGroup.MarginLayoutParams(Context c,AttributeSet attrs)

创建一个新的布局参数集合。这些值是从提供的属性集合和 context 中提取的。

参数

c 应用的环境

attrs 来自于布局参数的属性集合

public ViewGroup.MarginLayoutParams(int width,int height)

public ViewGroup.MarginLayoutParams(ViewGroup.MarginLayoutParams source)

复制构造方法。克隆 source 的宽、高和 margin 值。

参数

source 克隆的对象

Public Methods(公共方法)

public int getLayoutDirection()

返回布局的方向。可以是 LAYOUT_DIRECTION_LTR 或是 LAYOUT_DIRECTION_RTL 。

返回值

int 布局的方向

public int getMarginEnd()

返回以象素为单位的结尾 margin 值。

相关的 XML 属性值

android:layout_marginEnd

返回值

int 以象素为单位的结尾 margin 值

public int getMarginStart()

返回以象素为单位的开始的 margin 值。

相关的 XML 属性值

android:layout_marginStart

返回值

int 以象素为单位的开始 margin 值

public boolean isMarginRelative()

检查 margin 是否相对。

相关的 XML 属性

android:layout_marginStart

android:layout_marginEnd

返回值

boolean marginStart 或 marginEnd 已经设定,返回 true

public void resolveLayoutDirection(int layoutDircetion)

由 requestLayout()方法调用。根据布局的方向可以重写左右 margin 的值。

参数

layoutDircetion 布局的方向值(int)

public void setLayoutDircetion(int layoutDirection)

设置布局的方向。

参数

layoutDirection 布局的方向。LAYOUT_DIRECTION_LTR 或是 LAYOUT_DIRECTION_RTL

public void setMarginEnd(int end)

设置相对结束 margin。margin 值应该是正数。

相关的 XML 属性

android:layout_marginEnd

参数

end 结束 margin 的值

public void setMarginStart(int start)

设置相对开始 margin。margin 值应该是正数。

相关的 XML 属性

android:layout_marginStart

参数

start 开始 margin 的值

public void setMargins(int left,int top,int right,int bottom)

设置 margin,以象素为单位。需要先调用 requestLayout() 方法,这样新的 margin 值才能被使用。根据布局的方向左右 margin 值可能会被重写。margin 值应该是正数。

相关的 XML 属性

android:layout_marginLeft

android:layout_marginTop

android:layout_marginRight

android:layout_marginBottom

参数

left 左 margin 值

top 上 margin 值

right 右 margin 值

bottom 下 margin 值

猜你喜欢

转载自blog.csdn.net/miao9999/article/details/74140413
今日推荐