How to Place an Imageview on Top of Another Imageview in Android

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

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

set an imageview over another imageview - xml

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

How to place ImageViews on top of another ImageView?

First of all, you shouldn't require nesting a RelativeLayout inside a ConstraintLayout. You will also likely want your ScrollView as the top level layout, with your root layout inside the ScrollView. Also, what is your intention with having a HorizontalScrollView nested within the ScrollView? Are you needing the view to scroll both vertically and horizontally?

Within a ConstraintLayout you can layout any views relative to each other or the parent ConstraintLayout view. This includes having some child views on top of other child views.

Another option would be to use a FrameLayout, which wraps the content of the background ImageView. Then use a LinearLayout to place the smaller views on top. For example:

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

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

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">

<ImageView
android:id="@+id/dot1"
android:layout_width="wrap_content"
android:layout_weight="wrap_content"
android:src="@drawable/dot" />

<ImageView
android:id="@+id/dot2"
android:layout_width="wrap_content"
android:layout_weight="wrap_content"
android:src="@drawable/dot" />

</LinearLayout>

</FrameLayout>

You may also need to use another vertical orientation LinearLayout to layout the dots along the strings in a fret. For example:

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

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

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical">


<ImageView
android:id="@+id/dot1"
android:layout_width="wrap_content"
android:layout_weight="wrap_content"
android:src="@drawable/dot" />

<ImageView
android:id="@+id/dot2"
android:layout_width="wrap_content"
android:layout_weight="wrap_content"
android:src="@drawable/dot" />

</LinearLayout>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical">


<ImageView
android:id="@+id/dot1"
android:layout_width="wrap_content"
android:layout_weight="wrap_content"
android:src="@drawable/dot" />

<ImageView
android:id="@+id/dot2"
android:layout_width="wrap_content"
android:layout_weight="wrap_content"
android:src="@drawable/dot" />

</LinearLayout>

</LinearLayout>

</FrameLayout>

You'll also need to add spaces where you don't want dots. For example:

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

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

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical">


<ImageView
android:id="@+id/dot1"
android:layout_width="wrap_content"
android:layout_weight="wrap_content"
android:src="@drawable/dot" />

<Space
android:layout_width="match_parent"
android:layout_height="@dimen/dot_size" />

<ImageView
android:id="@+id/dot2"
android:layout_width="wrap_content"
android:layout_weight="wrap_content"
android:src="@drawable/dot" />

</LinearLayout>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical">


<ImageView
android:id="@+id/dot1"
android:layout_width="wrap_content"
android:layout_weight="wrap_content"
android:src="@drawable/dot" />

<Space
android:layout_width="match_parent"
android:layout_height="@dimen/dot_size" />

<Space
android:layout_width="match_parent"
android:layout_height="@dimen/dot_size" />

<ImageView
android:id="@+id/dot2"
android:layout_width="wrap_content"
android:layout_weight="wrap_content"
android:src="@drawable/dot" />

</LinearLayout>

</LinearLayout>

</FrameLayout>

Where @dimen/dot_size is defined as the size of one of the dots.

There are several variations using different layout types you could use. ConstraintLayout has the advantage of requiring only a single root ViewGroup. But it might be easier to conceptualize and build the layout using the LinearLayouts similar to my examples.

Android imageview over another imageview

<RelativeLayout
android:layout_width="54dp"
android:layout_height="54dp"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp">

<ImageView
android:id="@+id/warning_circle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:src="@drawable/ic_warning_circle"/>

<ImageView
android:id="@+id/button_menu"
android:layout_width="44dp"
android:layout_height="44dp"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:padding="5dp"
android:src="@drawable/ic_menu"
android:background="@drawable/button_white_rounded"
android:elevation="4dp"
android:scaleType="fitXY"
android:adjustViewBounds="true"
android:tint="@color/colorText"/>


</RelativeLayout>

ImageView on top of another imageview in Android

hi try the following code it will help you i didn't make any changes. i simply add an ImageView to your layout.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LayoutforbgImage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:baselineAligned="false"
android:orientation="horizontal" >

<ImageView
android:id="@+id/your_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="@drawable/top_bar" />

<LinearLayout
android:id="@+id/LinearLayoutforImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:paddingLeft="5dp"
android:paddingTop="10dp"
tools:ignore="RtlSymmetry,RtlHardcoded" >

<ImageView
android:id="@+id/imageforprofile"
android:layout_width="60dp"
android:layout_height="60dp"
android:src="@drawable/images12" />
</LinearLayout>

<TextView
android:id="@+id/textforprofile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/LinearLayoutforImage"
android:gravity="left"
android:paddingLeft="5dp"
android:paddingTop="16dp"
android:text="My Name My Name"
android:textColor="#FFFFFF"
android:textStyle="bold"
tools:ignore="HardcodedText,RtlHardcoded,RtlSymmetry" />

<TextView
android:id="@+id/textforprofileemail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textforprofile"
android:layout_toRightOf="@+id/LinearLayoutforImage"
android:gravity="left"
android:paddingBottom="10dp"
android:paddingLeft="5dp"
android:text="myname@abc.com"
android:textColor="#FFFFFF"
android:textStyle="bold"
tools:ignore="HardcodedText,RtlHardcoded,RtlSymmetry" />

</RelativeLayout>

how to half overlap imageview on another imageview in android

Simply you can use RealtiveLayout and negative margins

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_landing"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/screen_background">


<ImageView
android:background="@color/black"
android:id="@+id/img_background"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher" />

<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_below="@+id/img_background"
android:layout_centerHorizontal="true"
android:layout_marginTop="-40dp"<!-- negative margin to half of height -->
android:src="@mipmap/ic_launcher" />

</RelativeLayout>

Position two image view on top of another

One option must be using a FrameLayout

Android Layout Tricks #3: Optimize by merging

or using a RelativeLayout

<RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content">
<ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/image_bottom"/>
<ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/image_top" android:layout_alignParentBottom="true" android:layout_alignParentRight="true"/>
</RelativeLayout>

Update: I found this @ Stackoverflow:
how to place an image over another one on android app?



Related Topics



Leave a reply



Submit