Is it possible to place one view over another in android?
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 simplest ViewGroup
and stacks the Views
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 using android:layout_gravity
while android:gravity
is used for centering the text itself within each box.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="100dp"
android:layout_height="100dp">
<TextView
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="top|left"
android:background="@android:color/holo_blue_light"
android:gravity="center"
android:text="First is below"/>
<TextView
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="bottom|right"
android:background="@android:color/holo_green_light"
android:gravity="center"
android:text=" Last is on top"/>
</FrameLayout>