How to make imageview over another view in Android ?

ยท 140 words ยท 1 minute read

There are at least 3 ways to put imageview on another imageview.

Simple Order ๐Ÿ”—

This way is just put the imageview after the other imageview in XML file. It is simple like that. The first view will be underneath the second one.

Using FrameLayout ๐Ÿ”—

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/t" />

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher" />

</FrameLayout>

The second image will be on top.

Put imageview on another imageview exactly ๐Ÿ”—

<RelativeLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:background="@color/white" >

    <ImageView
        android:id="@+id/inside_imageview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="5dip"
        android:layout_marginTop="5dip"
        android:src="@drawable/frame" />

      <ImageView
         android:id="@+id/outside_imageview"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_alignTop="@id/inside_imageview"
         android:layout_alignBottom="@id/inside_imageview"
         android:layout_alignLeft="@id/inside_imageview"
         android:layout_alignRight="@id/inside_imageview"
         android:scaleType="fitXY" />
  </RelativeLayout>

As you can see, the second imageview has those properties.

android:layout_alignTop="@id/inside_imageview"
android:layout_alignBottom="@id/inside_imageview"
android:layout_alignLeft="@id/inside_imageview"
android:layout_alignRight="@id/inside_imageview"

which make the second imageview take the same dimensions of the first imageview. The second imageView will be on top of the first.

Share:
waffarx cash back