Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set an imageview over another imageview - xml

I have two imageviews that I would like to set second imageview over first image like below image :

enter image description here

first image:

enter image description here

second image (moment) :

enter image description here

how can I do ?

I wrote below codes, but it does not works fine :

    <ImageView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"       
        android:scaleType="fitXY"
        android:src="@drawable/ic_moment"
        />

    <ImageView
         android:id="@+id/img_view_item_main_list"
         android:layout_width="fill_parent"
         android:layout_height="220dp"
         android:scaleType="fitXY"       
         android:src="@drawable/testtesttest" />

like image 322
S.M_Emamian Avatar asked Nov 04 '14 07:11

S.M_Emamian


3 Answers

Use Framelayout or use merge tag

eg:

<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>

second image comes on the top

like image 113
Aun Avatar answered Oct 05 '22 11:10

Aun


try to do something like as follows

<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>

Also you can visit how to place an image over another one on android app?

like image 24
Jitesh Upadhyay Avatar answered Oct 05 '22 12:10

Jitesh Upadhyay


Try this way,hope this will help you to solve your problem.

Take FrameLayout as parent and set top image layout gravity top and let.

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

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scaleType="fitXY"
        android:src="@drawable/ic_moment" />

    <ImageView
        android:id="@+id/img_view_item_main_list"
        android:layout_width="wrap_content"
        android:layout_height="220dp"
        android:scaleType="fitXY"
        android:layout_gravity="top|left"
        android:src="@drawable/testtesttest" />

</FrameLayout>
like image 29
Haresh Chhelana Avatar answered Oct 05 '22 12:10

Haresh Chhelana