Can we place a small view over another large view? For example, I have a VideoView which is playing a file in the background. Over this, somewhere in the middle/corner, I want to place another ImageView.
But in Linear/Relative Layout, views can be placed only one after another or relative to each other, and AbsoluteLayout is advised against. So what do I do?
FrameLayouts
let you pile each view on top of the one below. This can also be achieved with aRelativeLayout
.Just in case if you want to place a view on top of a ButtonView then use this;
android:elevation="7dp"
for the view which needs to be placed on top of the button.The
FrameLayout
is the simplestViewGroup
and stacks theViews
in the order they're defined in layout XML (or added programmatically); the first will be lower, and the last will be on top.Here is an example where two
Views
are stacked and offset to better illustrate the point:Here is the actual layout XML with the two overlapping
TextView
boxes. The offset of the two boxes is done usingandroid:layout_gravity
whileandroid:gravity
is used for centering the text itself within each box.You can also do it by using ConstraintLayout a new layout introduced by google.