Class FrameLayout

All Implemented Interfaces:
Drawable.Callback, ViewManager, ViewParent
Direct Known Subclasses:
FragmentContainerView, HorizontalScrollView, NestedScrollView, ScrollView

public class FrameLayout extends ViewGroup
FrameLayout is designed to block out an area on the screen to display a single item. Generally, FrameLayout should be used to hold a single child view, because it can be difficult to organize child views in a way that's scalable to different screen sizes without the children overlapping each other. You can, however, add multiple children to a FrameLayout and control their position within the FrameLayout by assigning gravity to each child.

Child views are drawn in a stack, with the most recently added child on top. The size of the FrameLayout is the size of its largest child (plus padding), visible or not (if the FrameLayout's parent permits). Views that are View.GONE are used for sizing only if setMeasureAllChildren(boolean) is set to true.

Since:
2.0
  • Constructor Details

  • Method Details

    • setForegroundGravity

      public void setForegroundGravity(int foregroundGravity)
      Describes how the foreground is positioned. Defaults to START and TOP.
      Overrides:
      setForegroundGravity in class View
      Parameters:
      foregroundGravity - See Gravity
      See Also:
    • onMeasure

      protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
      Description copied from class: View
      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 overridden 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 super.onMeasure() 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 the base one to provide better measurements of their content.

      Overrides:
      onMeasure in class View
      Parameters:
      widthMeasureSpec - width measure specification imposed by the parent MeasureSpec
      heightMeasureSpec - height measure specification imposed by the parent MeasureSpec
    • onLayout

      protected void onLayout(boolean changed, int left, int top, int right, int bottom)
      Description copied from class: View
      Called from View.layout(int, int, int, int) 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.

      Specified by:
      onLayout in class ViewGroup
      Parameters:
      changed - This is a new size or position for this view
      left - Left position, relative to parent
      top - Top position, relative to parent
      right - Right position, relative to parent
      bottom - Bottom position, relative to parent
    • setMeasureAllChildren

      public void setMeasureAllChildren(boolean measureAll)
      Sets whether to consider 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.
    • getMeasureAllChildren

      public boolean getMeasureAllChildren()
      Determines whether all children, or just those in the VISIBLE or INVISIBLE state, are considered when measuring.
      Returns:
      Whether all children are considered when measuring.
    • generateLayoutParams

      @NonNull protected ViewGroup.LayoutParams generateLayoutParams(@NonNull ViewGroup.LayoutParams params)
      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(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:
      params - 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
    • generateDefaultLayoutParams

      @NonNull protected ViewGroup.LayoutParams generateDefaultLayoutParams()
      Returns a set of layout parameters with a width of ViewGroup.LayoutParams.MATCH_PARENT, and a height of ViewGroup.LayoutParams.MATCH_PARENT.
      Overrides:
      generateDefaultLayoutParams in class ViewGroup
      Returns:
      a set of default layout parameters
    • checkLayoutParams

      protected boolean checkLayoutParams(@Nullable ViewGroup.LayoutParams params)
      Description copied from class: ViewGroup
      Check whether given params fit to this view group.

      See also ViewGroup.generateLayoutParams(LayoutParams) See also ViewGroup.generateDefaultLayoutParams()

      Overrides:
      checkLayoutParams in class ViewGroup
      Parameters:
      params - layout params to check
      Returns:
      if params matched to this view group