1

I want to place 2 ImageViews, one above the other. Here is an example with a square and a circle.

enter image description here

How can I do that? I know only in runtime what images to use, so I cannot specify them in an xml file.

Thank you in advance.

Daniele Vitali
  • 3,848
  • 8
  • 48
  • 71

2 Answers2

4

You can use FrameLayout to stack views on each other.

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <ImageView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:src="@drawable/img_green" />
    <ImageView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:src="@drawable/img_red"/>
</FrameLayout>

then you may set android:layout_margin="" to properly position the ImageViews.

Note that the last child of FrameLayout is the top most visible view

anonim
  • 2,494
  • 6
  • 30
  • 40
0

You should specify their location inside the layout programmatically, this is not exactly what you are asking for, but you will get an idea of what you have to do :

How to create a RelativeLayout programmatically with two buttons one on top of the other?

Since absolute layout is deprecated you probably have to play with margins.

Community
  • 1
  • 1
Jachu
  • 405
  • 5
  • 10