Arturs Vancans
Arturs Vancans

Reputation: 4640

How to put images on each other without Absolute Layout in Android?

Basically the title speaks for itself. I would like to put elements on top of different elements. I could use Absolute Layout, but it is said to be deprecated.

Is there any other way to do it? And if no, why would they deprecate AbsoluteLayout?

Upvotes: 2

Views: 1870

Answers (2)

FoamyGuy
FoamyGuy

Reputation: 46856

The default behavior of RelativeLayout will stack all of the elements on top of each other in the top left corner so this layout:

<RelativeLayout
android:width="fill_parent"
android:height="fillparent">

<ImageView
android:width="wrap_content"
android:height="wrap_content"
android:src="@drawable/img1" />

<ImageView
android:width="wrap_content"
android:height="wrap_content"
android:src="@drawable/img2" />

</RelativeLayout>

Will stack the two images one ontop of the other in the top left of the screen. Relative layout offers many other attributes that will allow you to move the views to different positions on the screen. But the idea is that it scales to different sizes better because you won't be hardcoding x,y values for where you want elements to go.

Upvotes: 7

Aerilys
Aerilys

Reputation: 1639

I'm pretty sure you can make this kind of operation with a RelativeLayout.

Here is the doc : http://developer.android.com/reference/android/widget/RelativeLayout.html

Upvotes: 0

Related Questions