What does FrameLayout do?
You use a FrameLayout to stack child views on top of each other, with the most recent child on top of the stack. In the example below, the TextView is the most recent, so it is automatically placed on top of the ImageView.
For example:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <ImageView android:id="@+id/backgroundImage" android:layout_width="wrap_content" android:layout_height="wrap_content" android:scaleType="centerCrop" android:src="@drawable/bitmapie" /> <TextView android:id="@+id/descTextView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_marginTop="70dp" android:background="@android:color/holo_blue_light" android:padding="10dp" android:text="TextView placed at the top of the Imageview" android:textColor="@android:color/white" android:textSize="22sp" /></FrameLayout>
Output:
FrameLayout
is the simplest implementation of ViewGroup
. Child views are drawn are in a stack, where the latest added view is drawn at the top. Usually you can use one of the next approaches or combine them:
- Add a single view hierarchy into
FrameLayout
- Add multiple children and use
android:layout_gravity
to navigate them
Another popular approaches of using FrameLayout
:
- as a
Fragment
container - as an ancestor of your custom
ViewGroup
You can consider the word frame
as regular photo frame. What you do with that frame? you can place photos in that frame by one top to another. Same as in FrameLayout
we can place views ( Any layout, or widget like button, text, image so on) top of other as @ojonugwa shows you the textview top of the Image.