Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

image over another image

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

enter image description here

I want this first image over this second image.so that it looks like that this first image is standing over second image

like image 616
Anirban Avatar asked May 17 '26 10:05

Anirban


2 Answers

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" />
like image 152
Bojan Ilievski Avatar answered May 19 '26 22:05

Bojan Ilievski


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

like image 21
patel Avatar answered May 19 '26 23:05

patel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!