Reputation: 4632
I have 2 image I want to put one image over another my xml follows
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/imgThumb"
android:layout_width="60dip"
android:layout_height="80dip"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20sp"
android:src="@drawable/bg" />
<TextView
android:id="@+id/imgText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dip"
android:ellipsize="marquee"
android:singleLine="true"
android:text="test string"
android:textColor="#000000"
android:textSize="10dip"
android:visibility="gone" />
<View
android:layout_width="fill_parent"
android:layout_height="30sp"
android:background="@drawable/shelf" />
Layout looks like this
I want this first image over this second image.so that it looks like that this first image is standing over second image
Upvotes: 3
Views: 3944
Reputation: 1421
Change the LinearLayout to RelativeLayout, switch the places of the 2 images.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<View
android:id="@+id/shelf"
android:layout_below="@+id/imgThumb"
android:layout_width="fill_parent"
android:layout_height="30sp"
android:background="@drawable/shelf" />
<ImageView
android:id="@+id/imgThumb"
android:alignParentTop="true"
android:layout_width="60dip"
android:layout_height="80dip"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20sp"
android:src="@drawable/bg" />
Upvotes: 2
Reputation: 133560
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="138dp"
android:layout_marginTop="142dp"
android:src="@drawable/ic_launcher" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/imageView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"
android:src="@drawable/ic_launcher" />
<ImageView
android:id="@+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/imageView2"
android:layout_alignTop="@+id/imageView2"
android:layout_marginTop="15dp"
android:src="@drawable/ic_launcher" />
</RelativeLayout>
Upvotes: 1
Reputation: 850
Change Layout Linear to Relative or FramLayout and add Margin Top in views. In relative layout each and every control Automatically over its above control. Try below code.
<ImageView
android:id="@+id/imgThumb"
android:layout_width="60dip"
android:layout_height="80dip"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20sp"
android:src="@drawable/abc" />
<TextView
android:id="@+id/imgText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dip"
android:ellipsize="marquee"
android:singleLine="true"
android:text="test string"
android:textColor="#000000"
android:textSize="10dip"
android:visibility="gone" />
<View
android:layout_width="fill_parent"
android:layout_height="30sp"
android:layout_marginTop="20sp"
android:background="@drawable/ic_launcher" />
Upvotes: 2