How to place an imageview on top of another imageview in android-ThrowExceptions

Exception or error:

This is my layout which i tried so far without any success

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

 <LinearLayout 
    android:id="@+id/lltest" 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:layout_centerHorizontal="true">

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

</LinearLayout>

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

What i exactly want is to have my outside_imageview on top of inside_imageview with the exact height and width… How to do it through layout?

How to solve:
    <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>

The layout_align[Top|Bottom|Left|Right] attribute in RelativeLayout is used to align views based on their respective x and y values within the margin. The second ImageView will now be aligned to the top, bottom, left, and right of the first ImageView based on the margins. Padding is ignored in the alignment.

###

FrameLayout is what you need. You can simply merge the parent layout that is a FrameLayout too.
Take a look at the Android Developers Blog: http://android-developers.blogspot.it/2009/03/android-layout-tricks-3-optimize-by.html

<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center">

    <ImageView
        android:id="@+id/outside_imageview" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scaleType="fitXY"/>

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

###

You should try a FrameLayout. Inside a FrameLayout every Child is on top of each other.

###

I tried this way and it worked for me,hope it helps

 <FrameLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:padding="5dip">
<ImageView
    android:id="@+id/image_first"
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/imga"/>
<ImageView
    android:id="@+id/imageview"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:src="@drawable/image"/>
</FrameLayout>

###

                <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:padding="@dimen/_15dp">
                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:padding="@dimen/_10dp"
                    android:layout_marginTop="@dimen/_50dp"
                    android:background="@drawable/white_background"
                   />
                <ImageView
                    android:layout_width="@dimen/_100dp"
                    android:layout_height="@dimen/_100dp"
                    android:background="@drawable/my_credit"
                    android:layout_marginTop="@dimen/_5dp"
                    android:layout_centerHorizontal="true"
                    />
            </RelativeLayout>

###

I use Elevation only… 0=floor or basement … lol 1=floor2 10=floor10 the top top

    <ImageView
          android:id="@+id/blog_user_image_gp"
          android:layout_width="match_parent"
          android:layout_height="200dp"
          android:layout_marginTop="70dp"
          android:src="@drawable/avatar"
          android:scaleType="fitXY"
          android:foregroundGravity="center"
          android:elevation="10dp"
          />
  <android.support.v7.widget.RecyclerView
        android:id="@+id/users_list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="80dp"
        android:elevation="1dp"
        android:scrollbars="vertical" />

###

Just add translation z and it will be on top, make sure the translation z is greater than the view you want to be on top of. Sorry for the late response.

Leave a Reply

Your email address will not be published. Required fields are marked *