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, using the android:layout_gravity attribute.
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 GONE are used for sizing only if setConsiderGoneChildrenWhenMeasuring() is set to true.
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/frame" android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content" android:measureAllChildren="true" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:visibility="gone" android:src="@drawable/ic_launcher"/> </FrameLayout>
android:id: This is the ID which uniquely identifies the layout.
android:foreground: This defines the drawable to draw over the content and possible values may be a color value, in the form of “#rgb”, “#argb”, “#rrggbb”, or “#aarrggbb”.
android:foregroundGravity: Defines the gravity to apply to the foreground drawable. The gravity defaults to fill. Possible values are top, bottom, left, right, center, center_vertical, center_horizontal etc.
android:measureAllChildren: Determines whether to measure all children or just those in the VISIBLE or INVISIBLE state when measuring. Defaults to false.