Home » Android » java – how to half overlap imageview on another imageview in android

java – how to half overlap imageview on another imageview in android

Posted by: admin June 15, 2020 Leave a comment

Questions:

enter image description here

how can I overlap images half on one another from layout XML file like this image.

How to&Answers:

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>

Answer:

This can be achieve easily by RelativeLayout but you need to look about CoordinatorLayout and its features.

Answer:

<RelativeLayout
                android:layout_width="@dimen/_90sdp"
                android:layout_height="@dimen/_90sdp">

                <ImageView
                    android:id="@+id/bg"
                    android:layout_width="match_parent"
                    android:layout_height="@dimen/_90sdp"
                    android:background="@color/profile_bg"
                    android:scaleType="fitXY" />

                <ImageView
                    android:id="@+id/img_user"
                    android:layout_width="@dimen/_80sdp"
                    android:layout_height="@dimen/_80sdp"
                    android:layout_below="@+id/bg"
                    android:layout_centerHorizontal="true"
                    android:layout_marginTop="@dimen/_minus50sdp"
                    android:src="@drawable/place_holder_profile"/>
    </RelativeLayout>

Use this dependencies compile ‘com.intuit.sdp:sdp-android:1.0.2’
https://github.com/intuit/sdp

Answer:

You have to set the margin Top with minus(-) values.It will overlap your image view with other

Answer:

The FrameLayout is more optimised to perform this function. I carries less overhead.

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


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

    <ImageView
        android:layout_width="160dp"
        android:layout_height="160dp"
        android:layout_below="@+id/img_background"
        android:layout_gravity="bottom|center_horizontal"
        android:src="@mipmap/ic_launcher"
        android:background="@color/cardview_dark_background"/>

</FrameLayout>

Answer:

try this, it look like this
enter image description here

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

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

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1">

            <de.hdodenhof.circleimageview.CircleImageView
                android:id="@+id/profile_image"
                android:layout_width="96dp"
                android:layout_height="96dp"
                android:src="@drawable/cc"
                app:civ_border_width="2dp"
                app:civ_border_color="#FF000000"
                android:layout_centerInParent="true"
                />

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

                <FrameLayout
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_weight="1">
                    <ImageView
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:alpha="0.4"
                        android:src="@drawable/a123123t"/>

                </FrameLayout>

                <FrameLayout
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_weight="1">
                    <!--blank space-->

                </FrameLayout>


            </LinearLayout>

        </RelativeLayout>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:orientation="vertical">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:orientation="horizontal">
                <FrameLayout
                    android:layout_width="0dp"
                    android:layout_weight="1"
                    android:layout_height="match_parent">
                    <de.hdodenhof.circleimageview.CircleImageView
                        android:id="@+id/profile_image1"
                        android:layout_width="96dp"
                        android:layout_height="96dp"
                        android:src="@drawable/cc"
                        android:padding="8dp"
                        android:layout_gravity="center"
                        app:civ_border_width="2dp"
                        app:civ_border_color="#FF000000"
                        android:layout_centerInParent="true"
                        />

                </FrameLayout>

                <FrameLayout
                    android:layout_width="0dp"
                    android:layout_weight="1"
                    android:layout_height="match_parent">
                    <de.hdodenhof.circleimageview.CircleImageView
                        android:id="@+id/profile_image2"
                        android:layout_width="96dp"
                        android:layout_height="96dp"
                        android:src="@drawable/cc"
                        android:padding="8dp"
                        android:layout_gravity="center"
                        app:civ_border_width="2dp"
                        app:civ_border_color="#FF000000"
                        android:layout_centerInParent="true"
                        />

                </FrameLayout>

                <FrameLayout
                    android:layout_width="0dp"
                    android:layout_weight="1"
                    android:layout_height="match_parent">

                    <de.hdodenhof.circleimageview.CircleImageView
                        android:id="@+id/profile_image3"
                        android:layout_width="96dp"
                        android:layout_height="96dp"
                        android:src="@drawable/cc"
                        android:padding="8dp"
                        android:layout_gravity="center"
                        app:civ_border_width="2dp"
                        app:civ_border_color="#FF000000"
                        android:layout_centerInParent="true"
                        />
                </FrameLayout>






            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:orientation="vertical">

                <android.support.v4.widget.Space
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_weight="1" />

                <Button
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Edit Profile"/>
            </LinearLayout>

        </LinearLayout>



    </LinearLayout>

</LinearLayout>

for dependencies :

compile ‘de.hdodenhof:circleimageview:2.1.0’

Answer:

try this on

<RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/layout_background">
        <ImageView
            android:id="@+id/img_background"
            android:layout_width="match_parent"
            android:layout_height="108dp"
            android:background="@color/up"
            android:src="@mipmap/ic_launcher" />

        <de.hdodenhof.circleimageview.CircleImageView
            android:id="@+id/nav_header_view_profilePic"
            android:layout_width="108dp"
            android:layout_height="108dp"
            android:layout_below="@+id/img_background"
            android:src="@drawable/profile"
            android:layout_marginTop="-54dp"
            android:layout_centerHorizontal="true"
            />
    </RelativeLayout>

Answer:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/ll_mainProfile"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/gradientLeft"
    android:orientation="vertical"
    tools:context=".Activity.ProfileActivity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appBarLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar_profileActivity"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@drawable/side_nav_bar"
            app:popupTheme="@style/AppTheme.PopupOverlay"
            app:titleTextColor="@color/white" />

    </android.support.design.widget.AppBarLayout>


    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <RelativeLayout
            android:id="@+id/layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">


            <ImageView
                android:id="@+id/header_cover_image"
                android:layout_width="match_parent"
                android:layout_height="250dp"
                android:background="?attr/selectableItemBackgroundBorderless"
                android:scaleType="centerCrop"
                android:src="@drawable/background" />

            <ImageView
                android:id="@+id/img_profile"
                android:layout_width="200dp"
                android:layout_height="200dp"
                android:layout_below="@+id/header_cover_image"
                android:layout_centerHorizontal="true"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="-130dp"
                android:elevation="5dp"
                android:scaleType="centerCrop"
                android:src="@drawable/ic_profile" />

            <RelativeLayout
                android:id="@+id/profile_layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/header_cover_image"
                android:elevation="4dp"
                android:paddingBottom="24dp">


                <ImageView
                    android:id="@+id/img_editProfile"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentEnd="true"
                    android:layout_marginStart="16dp"
                    android:layout_marginTop="20dp"
                    android:layout_marginEnd="16dp"
                    android:layout_marginBottom="30dp"
                    android:clickable="true"
                    android:src="@android:drawable/ic_menu_edit"
                    android:visibility="gone" />

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/img_editProfile"
                    android:gravity="center_horizontal"
                    android:orientation="vertical"
                    android:layout_marginTop="80dp"
                    android:paddingStart="20dp"
                    android:paddingEnd="20dp">


                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal"
                        android:layout_marginBottom="10dp">

                        <EditText
                            android:id="@+id/et_fnameProfile"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:backgroundTint="@color/black_overlay"
                            android:editable="true"
                            android:hint="@string/hint_first_name"
                            android:inputType="textPersonName"
                            android:paddingStart="10dp"
                            android:paddingEnd="10dp"
                            android:textColor="@color/white"
                            android:textColorHint="@color/white"
                            android:textSize="18sp" />

                        <EditText
                            android:id="@+id/et_lnameProfile"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:backgroundTint="@color/black_overlay"
                            android:editable="true"
                            android:hint="@string/hint_last_name"
                            android:inputType="textPersonName"
                            android:paddingStart="10dp"
                            android:paddingEnd="10dp"
                            android:textColor="@color/white"
                            android:textColorHint="@color/white"
                            android:textSize="18sp" />

                    </LinearLayout>

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal"
                        android:layout_marginBottom="10dp">
                    <EditText
                        android:id="@+id/et_countryCodeProfile"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:backgroundTint="@color/black_overlay"
                        android:editable="true"
                        android:hint="@string/hint_country_code"
                        android:inputType="number"
                        android:paddingStart="10dp"
                        android:paddingEnd="10dp"
                        android:textColor="@color/white"
                        android:textColorHint="@color/white"
                        android:textSize="18sp" />


                    <EditText
                        android:id="@+id/et_mobileNoProfile"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:backgroundTint="@color/black_overlay"
                        android:editable="true"
                        android:hint="@string/hint_mobile_no"
                        android:inputType="number"
                        android:paddingStart="10dp"
                        android:paddingEnd="10dp"
                        android:textColor="@color/white"
                        android:textColorHint="@color/white"
                        android:textSize="18sp" />
                    </LinearLayout>
                </LinearLayout>

                <ProgressBar
                    android:id="@+id/progress_profile"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true" />
            </RelativeLayout>

        </RelativeLayout>

    </ScrollView>

</LinearLayout>