Benfactor
Benfactor

Reputation: 599

Put layout over another layout in constraint layout

I wan't to make layout like this:

Expected

When I am create constraint layout, it put images center of top align of modalview.

I created

Finally I do it, but I can not change align of title to bottom of image, because it present in parent layout.

How can I create layout like in first image?

Upvotes: 0

Views: 182

Answers (2)

Johny Alam
Johny Alam

Reputation: 377

Try to implement the below example might could work

layout_bg.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android">
        <solid android:color="#1D2126"/>
        <stroke android:width="3dp" android:color="#B1BCBE" />
        <corners android:radius="10dp"/>
        <padding android:left="0dp" android:top="0dp" android:right="0dp" android:bottom="0dp" />
    </shape>


    <androidx.constraintlayout.widget.ConstraintLayout 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"
        android:layout_margin="10dp"
        android:layout_gravity="center"
        android:foregroundGravity="center">

        <RelativeLayout
            android:id="@+id/imv_background_pic"
            android:layout_width="300dp"
            android:layout_height="400dp"
            android:background="@drawable/layout_bg"
            android:foregroundGravity="center"
            tools:ignore="MissingConstraints"
            tools:layout_editor_absoluteX="46dp"
            tools:layout_editor_absoluteY="198dp" />

        <ImageView
            android:id="@+id/imv_forground_pic"
            android:layout_width="200dp"
            android:layout_height="200dp"
            android:background="@drawable/layout_bg"
            android:foregroundGravity="center"
            tools:ignore="MissingConstraints"
            tools:layout_editor_absoluteX="96dp"
            tools:layout_editor_absoluteY="96dp" />


    </androidx.constraintlayout.widget.ConstraintLayout>

Upvotes: 1

Hardik Talaviya
Hardik Talaviya

Reputation: 1496

Try this

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="10dp">

    <!--Your Details Screen Layout-->
    <RelativeLayout
        android:id="@+id/rlMain"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="40dp">

    </RelativeLayout>

    <!--Your Top Image View-->
    <androidx.cardview.widget.CardView
        android:id="@+id/cardImg"
        android:layout_width="125dp"
        android:layout_height="150dp"
        android:layout_centerInParent="true"
        app:cardCornerRadius="5dp"
        app:cardElevation="10dp">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">
            <ImageView
                android:id="@+id/imgGame"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="fitXY" />
        </LinearLayout>
    </androidx.cardview.widget.CardView>
</RelativeLayout>

I hope this can help You!

Thank You.

Upvotes: 1

Related Questions