Most visited

Recently visited

Added in API level 1

FrameLayout

public class FrameLayout
extends ViewGroup

java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ android.widget.FrameLayout
Known Direct Subclasses
Known Indirect Subclasses


FrameLayout旨在阻挡屏幕上的某个区域以显示单个项目。 通常情况下,应该使用FrameLayout来保存单个子视图,因为可以很容易地组织子视图,这种方式可以根据不同的屏幕尺寸进行扩展,而不需要儿童相互重叠。 但是,您可以通过使用android:layout_gravity属性将多个孩子添加到FrameLayout并通过为每个孩子分配重力来控制他们在FrameLayout中的位置。

子视图以堆叠形式绘制,最近添加的子项位于顶部。 FrameLayout的大小是其最大子项(加上填充)的大小,可见与否(如果FrameLayout的父级允许)。 仅当setConsiderGoneChildrenWhenMeasuring()设置为true时,才使用视图GONE进行大小调整。

Summary

Nested classes

class FrameLayout.LayoutParams

支持边距的布局的每个子布局信息。

XML attributes

android:foregroundGravity Defines the gravity to apply to the foreground drawable. 
android:measureAllChildren Determines whether to measure all children or just those in the VISIBLE or INVISIBLE state when measuring. 

Inherited XML attributes

From class android.view.ViewGroup
From class android.view.View

Inherited constants

From class android.view.ViewGroup
From class android.view.View

Inherited fields

From class android.view.View

Public constructors

FrameLayout(Context context)
FrameLayout(Context context, AttributeSet attrs)
FrameLayout(Context context, AttributeSet attrs, int defStyleAttr)
FrameLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)

Public methods

FrameLayout.LayoutParams generateLayoutParams(AttributeSet attrs)

根据提供的属性集返回一组新的布局参数。

CharSequence getAccessibilityClassName()

返回此对象的类名称以用于辅助功能。

boolean getConsiderGoneChildrenWhenMeasuring()

此方法在API级别14中已弃用。此方法已弃用,用于getMeasureAllChildren() ,该方法已重命名为与setMeasureAllChildren()一致。

boolean getMeasureAllChildren()

确定是否在测量时考虑所有的孩子,或者只是那些处于VISIBLE或INVISIBLE状态的孩子。

void setForegroundGravity(int foregroundGravity)

描述前景如何定位。

void setMeasureAllChildren(boolean measureAll)

测量时设置是否考虑所有儿童,或仅考虑处于VISIBLE或INVISIBLE状态的儿童。

boolean shouldDelayChildPressedState()

如果应该延迟此ViewGroup的子项或后代的按下状态,则返回true。

Protected methods

boolean checkLayoutParams(ViewGroup.LayoutParams p)
FrameLayout.LayoutParams generateDefaultLayoutParams()

返回一组宽度为 MATCH_PARENT ,高度为 MATCH_PARENT的布局参数。

ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams lp)

根据提供的布局参数返回一组安全的布局参数。

void onLayout(boolean changed, int left, int top, int right, int bottom)

当这个视图为每个孩子分配一个大小和位置时,从布局调用。

void onMeasure(int widthMeasureSpec, int heightMeasureSpec)

测量视图及其内容以确定测量宽度和测量高度。

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

XML attributes

android:foregroundGravity

定义应用于前景绘制的重力。 重力缺省为填充。

必须是以下常量值中的一个或多个(用'|'分隔)。

Constant Value 描述
top 0x30 Push object to the top of its container, not changing its size.
bottom 0x50 Push object to the bottom of its container, not changing its size.
left 0x03 Push object to the left of its container, not changing its size.
right 0x05 Push object to the right of its container, not changing its size.
center_vertical 0x10 Place object in the vertical center of its container, not changing its size.
fill_vertical 0x70 Grow the vertical size of the object if needed so it completely fills its container.
center_horizontal 0x01 Place object in the horizontal center of its container, not changing its size.
fill_horizontal 0x07 Grow the horizontal size of the object if needed so it completely fills its container.
center 0x11 Place the object in the center of its container in both the vertical and horizontal axis, not changing its size.
fill 0x77 Grow the horizontal and vertical size of the object if needed so it completely fills its container.
clip_vertical 0x80 Additional option that can be set to have the top and/or bottom edges of the child clipped to its container's bounds. The clip will be based on the vertical gravity: a top gravity will clip the bottom edge, a bottom gravity will clip the top edge, and neither will clip both edges.
clip_horizontal 0x08 Additional option that can be set to have the left and/or right edges of the child clipped to its container's bounds. The clip will be based on the horizontal gravity: a left gravity will clip the right edge, a right gravity will clip the left edge, and neither will clip both edges.

这对应于全局属性资源符号 foregroundGravity

相关方法:

android:measureAllChildren

确定是在测量时测量所有孩子还是只测量VISIBLE或INVISIBLE状态的孩子。 默认为false。

必须是布尔值,即“ true ”或“ false ”。

这也可能是对包含此类型值的资源(形式为“ @[package:]type:name ”)或主题属性(形式为“ ?[package:][type:]name ”)的 ?[package:][type:]name

这对应于全局属性资源符号 measureAllChildren

相关方法:

Public constructors

FrameLayout

Added in API level 1
FrameLayout (Context context)

Parameters
context Context

FrameLayout

Added in API level 1
FrameLayout (Context context, 
                AttributeSet attrs)

Parameters
context Context
attrs AttributeSet

FrameLayout

Added in API level 1
FrameLayout (Context context, 
                AttributeSet attrs, 
                int defStyleAttr)

Parameters
context Context
attrs AttributeSet
defStyleAttr int

FrameLayout

Added in API level 21
FrameLayout (Context context, 
                AttributeSet attrs, 
                int defStyleAttr, 
                int defStyleRes)

Parameters
context Context
attrs AttributeSet
defStyleAttr int
defStyleRes int

Public methods

generateLayoutParams

Added in API level 1
FrameLayout.LayoutParams generateLayoutParams (AttributeSet attrs)

根据提供的属性集返回一组新的布局参数。

Parameters
attrs AttributeSet: the attributes to build the layout parameters from
Returns
FrameLayout.LayoutParams an instance of ViewGroup.LayoutParams or one of its descendants

getAccessibilityClassName

Added in API level 23
CharSequence getAccessibilityClassName ()

返回此对象的类名称以用于辅助功能。 如果子类正在实现的东西应该被视为一个全新的视图类,当它被可访问性使用时,子类只应该覆盖这个子类,与它所源自的类无关。 这用于填写AccessibilityNodeInfo.setClassName

Returns
CharSequence

getConsiderGoneChildrenWhenMeasuring

Added in API level 1
boolean getConsiderGoneChildrenWhenMeasuring ()

此方法在API级别14中已弃用。
此方法已弃用,用于getMeasureAllChildren() ,为了与setMeasureAllChildren()保持一致,重命名了此方法。

确定是否在测量时考虑所有的孩子,或者只是那些处于VISIBLE或INVISIBLE状态的孩子。

Returns
boolean Whether all children are considered when measuring.

getMeasureAllChildren

Added in API level 14
boolean getMeasureAllChildren ()

确定是否在测量时考虑所有的孩子,或者只是那些处于VISIBLE或INVISIBLE状态的孩子。

Returns
boolean Whether all children are considered when measuring.

setForegroundGravity

Added in API level 1
void setForegroundGravity (int foregroundGravity)

描述前景如何定位。 默认为START和TOP。

相关XML属性:

Parameters
foregroundGravity int: See Gravity

也可以看看:

setMeasureAllChildren

Added in API level 1
void setMeasureAllChildren (boolean measureAll)

测量时设置是否考虑所有儿童,或仅考虑处于VISIBLE或INVISIBLE状态的儿童。 默认为false。

相关XML属性:

Parameters
measureAll boolean: true to consider children marked GONE, false otherwise. Default value is false.

shouldDelayChildPressedState

Added in API level 14
boolean shouldDelayChildPressedState ()

如果应该延迟此ViewGroup的子项或后代的按下状态,则返回true。 通常,这应该对可以滚动的容器(例如List)完成。 这可以防止在用户实际尝试滚动内容时出现按下状态。 出于兼容性原因,默认实现返回true。 不滚动的子类通常应该重写此方法并返回false。

Returns
boolean

Protected methods

checkLayoutParams

Added in API level 1
boolean checkLayoutParams (ViewGroup.LayoutParams p)

Parameters
p ViewGroup.LayoutParams
Returns
boolean

generateDefaultLayoutParams

Added in API level 1
FrameLayout.LayoutParams generateDefaultLayoutParams ()

返回一组宽度为 MATCH_PARENT ,高度为 MATCH_PARENT的布局参数。

Returns
FrameLayout.LayoutParams a set of default layout parameters or null

generateLayoutParams

Added in API level 1
ViewGroup.LayoutParams generateLayoutParams (ViewGroup.LayoutParams lp)

根据提供的布局参数返回一组安全的布局参数。 当一个ViewGroup被传递了一个View,其布局参数没有通过checkLayoutParams(android.view.ViewGroup.LayoutParams)的测试时,这个方法被调用。 此方法应该返回一组适合此ViewGroup的布局参数,可能是通过从指定的一组布局参数中复制适当的属性。

Parameters
lp ViewGroup.LayoutParams: The layout parameters to convert into a suitable set of layout parameters for this ViewGroup.
Returns
ViewGroup.LayoutParams an instance of ViewGroup.LayoutParams or one of its descendants

onLayout

Added in API level 1
void onLayout (boolean changed, 
                int left, 
                int top, 
                int right, 
                int bottom)

当这个视图为每个孩子分配一个大小和位置时,从布局调用。 带孩子的派生类应该覆盖这个方法,并调用他们每个孩子的布局。

Parameters
changed boolean: This is a new size or position for this view
left int: Left position, relative to parent
top int: Top position, relative to parent
right int: Right position, relative to parent
bottom int: Bottom position, relative to parent

onMeasure

Added in API level 1
void onMeasure (int widthMeasureSpec, 
                int heightMeasureSpec)

测量视图及其内容以确定测量宽度和测量高度。 此方法由measure(int, int)调用, measure(int, int)子类覆盖以提供其内容的准确和有效的度量。

合同:覆盖此方法时, 必须致电setMeasuredDimension(int, int)来存储此视图的测量宽度和高度。 不这样做会触发IllegalStateException ,由measure(int, int)引发。 调用超类' onMeasure(int, int)是一种有效的用法。

Measure的基类实现默认为背景大小,除非MeasureSpec允许更大的大小。 子类应该覆盖onMeasure(int, int)以提供更好的内容度量。

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 int: horizontal space requirements as imposed by the parent. The requirements are encoded with View.MeasureSpec.
heightMeasureSpec int: vertical space requirements as imposed by the parent. The requirements are encoded with View.MeasureSpec.

Hooray!