Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add overlay view over other view in android?

I want to put button above image view.

How can i do this?

(Please, don't offer to set Background, cause i need ImageView)

like image 864
Urban Avatar asked Sep 24 '10 19:09

Urban


People also ask

How do I move one view to the top of another 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. Thanks.

What is Z index in Android?

Z-Index for Annotation Stacking Order on Android The annotation z-index defines the stacking order of annotations on a page.

What is overlay Android studio?

An overlay is an extra layer that sits on top of a View (the "host view") which is drawn after all other content in that view (including children, if the view is a ViewGroup). Interaction with the overlay layer is done by adding and removing drawables.


1 Answers

Set as background!

Just kidding... what you need is put your views inside a RelativeLayout. Something like will work:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
  <ImageView
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"/>
    <Button
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_alignParentLeft="true"
       android:layout_alignParentBottom="true"
       android:text="blah blah"/>
</RelativeLayout>

Notice the use of params like layout_alignParentLeft which are used to position the view where you want.

like image 104
Cristian Avatar answered Sep 21 '22 12:09

Cristian