0

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?

Benfactor
  • 543
  • 4
  • 11
  • 31
  • https://stackoverflow.com/questions/42984909/how-to-achieve-overlap-negative-margin-on-constraint-layout – AskNilesh Nov 04 '19 at 08:25
  • let them be in same layout. if you just made ImageView be ordered after modal view, it would cover background. – Choim Nov 04 '19 at 08:48

2 Answers2

1

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.

Hardik Talaviya
  • 1,396
  • 5
  • 18
1

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>
Jane Alam
  • 360
  • 2
  • 7