I want to place 2 ImageViews, one above the other. Here is an example with a square and a circle.
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.
I want to place 2 ImageViews, one above the other. Here is an example with a square and a circle.
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.
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 ImageView
s.
Note that the last child of FrameLayout
is the top most visible view
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.