android.widget
Class FrameLayout
java.lang.Object
android.view.View
android.view.ViewGroup
android.widget.FrameLayout
- All Implemented Interfaces:
- Drawable.Callback, KeyEvent.Callback, ViewManager, ViewParent
- Direct Known Subclasses:
- DatePicker, GadgetHostView, MediaController, ScrollView, TabHost, TimePicker, ViewAnimator
public class FrameLayout
- extends ViewGroup
FrameLayout is designed to block out an area on the screen to display
a single item. You can add multiple children to a FrameLayout, but all
children are pegged to the top left of the screen.
Children are drawn in a stack, with the most recently added child on top.
The size of the frame layout is the size of its largest child (plus padding), visible
or not (if the FrameLayout's parent permits). Views that are GONE are used for sizing
only if setConsiderGoneChildrenWhenMeasuring()
is set to true.
|
Nested Class Summary |
static class |
FrameLayout.LayoutParams
Per-child layout information for layouts that support margins. |
| Fields inherited from class android.view.ViewGroup |
CLIP_TO_PADDING_MASK, FLAG_SUPPORT_STATIC_TRANSFORMATIONS, FLAG_USE_CHILD_DRAWING_ORDER, FOCUS_AFTER_DESCENDANTS, FOCUS_BEFORE_DESCENDANTS, FOCUS_BLOCK_DESCENDANTS, mDisappearingChildren, mGroupFlags, mOnHierarchyChangeListener, mPersistentDrawingCache, PERSISTENT_ALL_CACHES, PERSISTENT_ANIMATION_CACHE, PERSISTENT_NO_CACHE, PERSISTENT_SCROLLING_CACHE |
| Fields inherited from class android.view.View |
DRAWING_CACHE_QUALITY_AUTO, DRAWING_CACHE_QUALITY_HIGH, DRAWING_CACHE_QUALITY_LOW, EMPTY_STATE_SET, ENABLED_FOCUSED_SELECTED_STATE_SET, ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, ENABLED_FOCUSED_STATE_SET, ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET, ENABLED_SELECTED_STATE_SET, ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET, ENABLED_STATE_SET, ENABLED_WINDOW_FOCUSED_STATE_SET, FIRST_STATE_SET, FOCUS_BACKWARD, FOCUS_DOWN, FOCUS_FORWARD, FOCUS_LEFT, FOCUS_RIGHT, FOCUS_UP, FOCUSED_SELECTED_STATE_SET, FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, FOCUSED_STATE_SET, FOCUSED_WINDOW_FOCUSED_STATE_SET, GONE, INVISIBLE, KEEP_SCREEN_ON, LAST_STATE_SET, mBottom, mContext, mCurrentAnimation, MIDDLE_STATE_SET, mLayoutParams, mLeft, mMeasuredHeight, mMeasuredWidth, mOnClickListener, mOnCreateContextMenuListener, mOnFocusChangeListener, mOnLongClickListener, mPaddingBottom, mPaddingLeft, mPaddingRight, mPaddingTop, mParent, mRight, mScrollX, mScrollY, mTag, mTop, NO_ID, PRESSED_ENABLED_FOCUSED_SELECTED_STATE_SET, PRESSED_ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_FOCUSED_STATE_SET, PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_SELECTED_STATE_SET, PRESSED_ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_STATE_SET, PRESSED_ENABLED_WINDOW_FOCUSED_STATE_SET, PRESSED_FIRST_STATE_SET, PRESSED_FOCUSED_SELECTED_STATE_SET, PRESSED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_FOCUSED_STATE_SET, PRESSED_FOCUSED_WINDOW_FOCUSED_STATE_SET, PRESSED_LAST_STATE_SET, PRESSED_MIDDLE_STATE_SET, PRESSED_SELECTED_STATE_SET, PRESSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_SINGLE_STATE_SET, PRESSED_STATE_SET, PRESSED_WINDOW_FOCUSED_STATE_SET, SCROLLBARS_INSIDE_INSET, SCROLLBARS_INSIDE_OVERLAY, SCROLLBARS_OUTSIDE_INSET, SCROLLBARS_OUTSIDE_OVERLAY, SELECTED_STATE_SET, SELECTED_WINDOW_FOCUSED_STATE_SET, SINGLE_STATE_SET, SOUND_EFFECTS_ENABLED, VIEW_LOG_TAG, VISIBLE, WINDOW_FOCUSED_STATE_SET |
|
Method Summary |
protected boolean |
checkLayoutParams(ViewGroup.LayoutParams p)
|
void |
draw(Canvas canvas)
Manually render this view (and all of its children) to the given Canvas. |
protected void |
drawableStateChanged()
This function is called whenever the state of the view changes in such
a way that it impacts the state of drawables being shown. |
boolean |
gatherTransparentRegion(Region region)
This is used by the RootView to perform an optimization when
the view hierarchy contains one or several SurfaceView. |
protected FrameLayout.LayoutParams |
generateDefaultLayoutParams()
Returns a set of layout parameters with a width of
ViewGroup.LayoutParams.FILL_PARENT,
and a height of ViewGroup.LayoutParams.FILL_PARENT. |
FrameLayout.LayoutParams |
generateLayoutParams(AttributeSet attrs)
Returns a new set of layout parameters based on the supplied attributes set. |
protected ViewGroup.LayoutParams |
generateLayoutParams(ViewGroup.LayoutParams p)
Returns a safe set of layout parameters based on the supplied layout params. |
boolean |
getConsiderGoneChildrenWhenMeasuring()
Determines whether to measure all children or just those in
the VISIBLE or INVISIBLE state when measuring. |
Drawable |
getForeground()
Returns the drawable used as the foreground of this FrameLayout. |
protected void |
onLayout(boolean changed,
int left,
int top,
int right,
int bottom)
Called from layout when this view should
assign a size and position to each of its children. |
protected void |
onMeasure(int widthMeasureSpec,
int heightMeasureSpec)
Measure the view and its content to determine the measured width and the
measured height. |
protected void |
onSizeChanged(int w,
int h,
int oldw,
int oldh)
This is called during layout when the size of this view has changed. |
void |
setForeground(Drawable drawable)
Supply a Drawable that is to be rendered on top of all of the child
views in the frame layout. |
void |
setForegroundGravity(int foregroundGravity)
Describes how the foreground is positioned. |
void |
setMeasureAllChildren(boolean measureAll)
Determines whether to measure all children or just those in
the VISIBLE or INVISIBLE state when measuring. |
protected boolean |
verifyDrawable(Drawable who)
If your view subclass is displaying its own Drawable objects, it should
override this function and return true for any Drawable it is
displaying. |
| Methods inherited from class android.view.ViewGroup |
addFocusables, addStatesFromChildren, addTouchables, addView, addView, addView, addView, addView, addViewInLayout, addViewInLayout, attachLayoutAnimationParameters, attachViewToParent, bringChildToFront, canAnimate, childDrawableStateChanged, cleanupLayoutState, clearChildFocus, clearDisappearingChildren, clearFocus, debug, detachAllViewsFromParent, detachViewFromParent, detachViewFromParent, detachViewsFromParent, dispatchDraw, dispatchFreezeSelfOnly, dispatchKeyEvent, dispatchKeyEventPreIme, dispatchKeyShortcutEvent, dispatchRestoreInstanceState, dispatchSaveInstanceState, dispatchSetPressed, dispatchSetSelected, dispatchThawSelfOnly, dispatchTouchEvent, dispatchTrackballEvent, dispatchUnhandledMove, dispatchWindowFocusChanged, dispatchWindowVisibilityChanged, drawChild, findFocus, findViewTraversal, findViewWithTagTraversal, fitSystemWindows, focusableViewAvailable, focusSearch, getChildAt, getChildCount, getChildDrawingOrder, getChildMeasureSpec, getChildStaticTransformation, getChildVisibleRect, getDescendantFocusability, getFocusedChild, getLayoutAnimation, getLayoutAnimationListener, getPersistentDrawingCache, hasFocus, hasFocusable, indexOfChild, invalidateChild, invalidateChildInParent, isAlwaysDrawnWithCacheEnabled, isAnimationCacheEnabled, isChildrenDrawnWithCacheEnabled, measureChild, measureChildren, measureChildWithMargins, offsetChildrenTopAndBottom, offsetDescendantRectToMyCoords, offsetRectIntoDescendantCoords, onAnimationEnd, onAnimationStart, onCreateDrawableState, onInterceptTouchEvent, onRequestFocusInDescendants, recomputeViewAttributes, removeAllViews, removeAllViewsInLayout, removeDetachedView, removeView, removeViewAt, removeViewInLayout, removeViews, removeViewsInLayout, requestChildFocus, requestChildRectangleOnScreen, requestDisallowInterceptTouchEvent, requestFocus, requestTransparentRegion, scheduleLayoutAnimation, setAddStatesFromChildren, setAlwaysDrawnWithCacheEnabled, setAnimationCacheEnabled, setChildrenDrawingCacheEnabled, setChildrenDrawnWithCacheEnabled, setClipChildren, setClipToPadding, setDescendantFocusability, setLayoutAnimation, setLayoutAnimationListener, setOnHierarchyChangeListener, setPadding, setPersistentDrawingCache, setStaticTransformationsEnabled, showContextMenuForChild, startLayoutAnimation, updateViewLayout |
| Methods inherited from class android.view.View |
applyDrawableToTransparentRegion, bringToFront, buildDrawingCache, cancelLongPress, clearAnimation, computeHorizontalScrollExtent, computeHorizontalScrollOffset, computeHorizontalScrollRange, computeScroll, computeVerticalScrollExtent, computeVerticalScrollOffset, computeVerticalScrollRange, createContextMenu, debug, debugIndent, destroyDrawingCache, finalize, findViewById, findViewWithTag, focusSearch, forceLayout, getAnimation, getApplicationWindowToken, getBackground, getBaseline, getBottom, getBottomFadingEdgeStrength, getBottomPaddingOffset, getContext, getContextMenuInfo, getDefaultSize, getDrawableState, getDrawingCache, getDrawingCacheBackgroundColor, getDrawingCacheQuality, getDrawingRect, getDrawingTime, getFocusables, getFocusedRect, getGlobalVisibleRect, getGlobalVisibleRect, getHandler, getHeight, getHitRect, getHorizontalFadingEdgeLength, getHorizontalScrollbarHeight, getId, getKeepScreenOn, getLayoutParams, getLeft, getLeftFadingEdgeStrength, getLeftPaddingOffset, getLocalVisibleRect, getLocationInWindow, getLocationOnScreen, getMeasuredHeight, getMeasuredWidth, getNextFocusDownId, getNextFocusLeftId, getNextFocusRightId, getNextFocusUpId, getOnFocusChangeListener, getPaddingBottom, getPaddingLeft, getPaddingRight, getPaddingTop, getParent, getResources, getRight, getRightFadingEdgeStrength, getRightPaddingOffset, getRootView, getScrollBarStyle, getScrollX, getScrollY, getSolidColor, getSuggestedMinimumHeight, getSuggestedMinimumWidth, getTag, getTop, getTopFadingEdgeStrength, getTopPaddingOffset, getTouchables, getTouchDelegate, getVerticalFadingEdgeLength, getVerticalScrollbarWidth, getViewTreeObserver, getVisibility, getWidth, getWindowAttachCount, getWindowToken, getWindowVisibility, getWindowVisibleDisplayFrame, hasWindowFocus, inflate, initializeFadingEdge, initializeScrollbars, invalidate, invalidate, invalidate, invalidateDrawable, isClickable, isDrawingCacheEnabled, isDuplicateParentStateEnabled, isEnabled, isFocusable, isFocusableInTouchMode, isFocused, isHorizontalFadingEdgeEnabled, isHorizontalScrollBarEnabled, isInEditMode, isInTouchMode, isLayoutRequested, isLongClickable, isPaddingOffsetRequired, isPressed, isRootNamespace, isSaveEnabled, isSelected, isShown, isSoundEffectsEnabled, isVerticalFadingEdgeEnabled, isVerticalScrollBarEnabled, layout, measure, mergeDrawableStates, offsetLeftAndRight, offsetTopAndBottom, onAttachedToWindow, onCheckIsTextEditor, onCreateContextMenu, onCreateInputConnection, onDetachedFromWindow, onDraw, onFinishInflate, onFocusChanged, onKeyDown, onKeyMultiple, onKeyPreIme, onKeyShortcut, onKeyUp, onRestoreInstanceState, onSaveInstanceState, onScrollChanged, onSetAlpha, onTouchEvent, onTrackballEvent, onWindowFocusChanged, onWindowVisibilityChanged, performClick, performLongClick, playSoundEffect, post, postDelayed, postInvalidate, postInvalidate, postInvalidateDelayed, postInvalidateDelayed, refreshDrawableState, removeCallbacks, requestFocus, requestFocus, requestFocusFromTouch, requestLayout, requestRectangleOnScreen, requestRectangleOnScreen, resolveSize, restoreHierarchyState, saveHierarchyState, scheduleDrawable, scrollBy, scrollTo, setAnimation, setBackgroundColor, setBackgroundDrawable, setBackgroundResource, setClickable, setDrawingCacheBackgroundColor, setDrawingCacheEnabled, setDrawingCacheQuality, setDuplicateParentStateEnabled, setEnabled, setFadingEdgeLength, setFocusable, setFocusableInTouchMode, setFrame, setHorizontalFadingEdgeEnabled, setHorizontalScrollBarEnabled, setId, setIsRootNamespace, setKeepScreenOn, setLayoutParams, setLongClickable, setMeasuredDimension, setMinimumHeight, setMinimumWidth, setNextFocusDownId, setNextFocusLeftId, setNextFocusRightId, setNextFocusUpId, setOnClickListener, setOnCreateContextMenuListener, setOnFocusChangeListener, setOnKeyListener, setOnLongClickListener, setOnTouchListener, setPressed, setSaveEnabled, setScrollBarStyle, setScrollContainer, setSelected, setSoundEffectsEnabled, setTag, setTouchDelegate, setVerticalFadingEdgeEnabled, setVerticalScrollBarEnabled, setVisibility, setWillNotCacheDrawing, setWillNotDraw, showContextMenu, startAnimation, unscheduleDrawable, unscheduleDrawable, willNotCacheDrawing, willNotDraw |
mMeasureAllChildren
boolean mMeasureAllChildren
FrameLayout
public FrameLayout(Context context)
FrameLayout
public FrameLayout(Context context,
AttributeSet attrs)
FrameLayout
public FrameLayout(Context context,
AttributeSet attrs,
int defStyle)
setForegroundGravity
public void setForegroundGravity(int foregroundGravity)
- Describes how the foreground is positioned. Defaults to FILL.
- Parameters:
foregroundGravity - See Gravity
verifyDrawable
protected boolean verifyDrawable(Drawable who)
- If your view subclass is displaying its own Drawable objects, it should
override this function and return true for any Drawable it is
displaying. This allows animations for those drawables to be
scheduled.
Be sure to call through to the super class when overriding this
function.
- Overrides:
verifyDrawable in class View
- Parameters:
who - The Drawable to verify. Return true if it is one you are
displaying, else return the result of calling through to the
super class.
- Returns:
- boolean If true than the Drawable is being displayed in the
view; else false and it is not allowed to animate.
- See Also:
View.unscheduleDrawable(android.graphics.drawable.Drawable, java.lang.Runnable),
View.drawableStateChanged()
drawableStateChanged
protected void drawableStateChanged()
- This function is called whenever the state of the view changes in such
a way that it impacts the state of drawables being shown.
Be sure to call through to the superclass when overriding this
function.
- Overrides:
drawableStateChanged in class ViewGroup
- See Also:
Drawable.setState(int[])
generateDefaultLayoutParams
protected FrameLayout.LayoutParams generateDefaultLayoutParams()
- Returns a set of layout parameters with a width of
ViewGroup.LayoutParams.FILL_PARENT,
and a height of ViewGroup.LayoutParams.FILL_PARENT.
- Overrides:
generateDefaultLayoutParams in class ViewGroup
- Returns:
- a set of default layout parameters or null
setForeground
public void setForeground(Drawable drawable)
- Supply a Drawable that is to be rendered on top of all of the child
views in the frame layout. Any padding in the Drawable will be taken
into account by ensuring that the children are inset to be placed
inside of the padding area.
- Parameters:
drawable - The Drawable to be drawn on top of the children.
getForeground
public Drawable getForeground()
- Returns the drawable used as the foreground of this FrameLayout. The
foreground drawable, if non-null, is always drawn on top of the children.
- Returns:
- A Drawable or null if no foreground was set.
onMeasure
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 View.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 View.setMeasuredDimension(int, int) to store the
measured width and height of this view. Failure to do so will trigger an
IllegalStateException, thrown by
View.measure(int, int). Calling the superclass'
View.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 View.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 (View.getSuggestedMinimumHeight() and
View.getSuggestedMinimumWidth()).
- Overrides:
onMeasure in class View
- 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.- See Also:
View.getMeasuredWidth(),
View.getMeasuredHeight(),
View.setMeasuredDimension(int, int),
View.getSuggestedMinimumHeight(),
View.getSuggestedMinimumWidth(),
View.MeasureSpec.getMode(int),
View.MeasureSpec.getSize(int)
onLayout
protected void onLayout(boolean changed,
int left,
int top,
int right,
int bottom)
- 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 their children.
- Specified by:
onLayout in class ViewGroup
- Parameters:
changed - This is a new size or position for this viewleft - Left position, relative to parenttop - Top position, relative to parentright - Right position, relative to parentbottom - Bottom position, relative to parent
onSizeChanged
protected void onSizeChanged(int w,
int h,
int oldw,
int oldh)
- This is called during layout when the size of this view has changed. If
you were just added to the view hierarchy, you're called with the old
values of 0.
- Overrides:
onSizeChanged in class View
- Parameters:
w - Current width of this view.h - Current height of this view.oldw - Old width of this view.oldh - Old height of this view.
draw
public void draw(Canvas canvas)
- Manually render this view (and all of its children) to the given Canvas.
The view must have already done a full layout before this function is
called. When implementing a view, do not override this method; instead,
you should implement
View.onDraw(android.graphics.Canvas).
- Overrides:
draw in class View
- Parameters:
canvas - The Canvas to which the View is rendered.
gatherTransparentRegion
public boolean gatherTransparentRegion(Region region)
- This is used by the RootView to perform an optimization when
the view hierarchy contains one or several SurfaceView.
SurfaceView is always considered transparent, but its children are not,
therefore all View objects remove themselves from the global transparent
region (passed as a parameter to this function).
- Overrides:
gatherTransparentRegion in class ViewGroup
- Parameters:
region - The transparent region for this ViewRoot (window).
- Returns:
- Returns true if the effective visibility of the view at this
point is opaque, regardless of the transparent region; returns false
if it is possible for underlying windows to be seen behind the view.
setMeasureAllChildren
public void setMeasureAllChildren(boolean measureAll)
- Determines whether to measure all children or just those in
the VISIBLE or INVISIBLE state when measuring. Defaults to false.
- Parameters:
measureAll - true to consider children marked GONE, false otherwise.
Default value is false.
getConsiderGoneChildrenWhenMeasuring
public boolean getConsiderGoneChildrenWhenMeasuring()
- Determines whether to measure all children or just those in
the VISIBLE or INVISIBLE state when measuring.
generateLayoutParams
public FrameLayout.LayoutParams generateLayoutParams(AttributeSet attrs)
- Returns a new set of layout parameters based on the supplied attributes set.
- Overrides:
generateLayoutParams in class ViewGroup
- Parameters:
attrs - the attributes to build the layout parameters from
- Returns:
- an instance of
ViewGroup.LayoutParams or one
of its descendants
checkLayoutParams
protected boolean checkLayoutParams(ViewGroup.LayoutParams p)
-
- Overrides:
checkLayoutParams in class ViewGroup
generateLayoutParams
protected ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams p)
- Description copied from class:
ViewGroup
- 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
ViewGroup.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.
- Overrides:
generateLayoutParams in class ViewGroup
- Parameters:
p - The layout parameters to convert into a suitable set of layout parameters
for this ViewGroup.
- Returns:
- an instance of
ViewGroup.LayoutParams or one
of its descendants
Please submit a feedback, bug or feature