Dusan Dimitrijevic
Dusan Dimitrijevic

Reputation: 3219

How to bring view in front of cardview?

I have one design pattern, but i'm not sure how could i create this. This is how it should looks:

enter image description here

I'm still struggling with putting image view in front of cardview. Any thoughts about that or example how this could be done? Thanks!

This is what i have done:

<RelativeLayout android:id="@+id/containor"
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:paddingBottom="@dimen/activity_vertical_margin"
            android:paddingLeft="@dimen/activity_horizontal_margin"
            android:paddingRight="@dimen/activity_horizontal_margin"
            android:paddingTop="@dimen/activity_vertical_margin">

<de.hdodenhof.circleimageview.CircleImageView
    android:id="@+id/iv_profile"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:layout_centerHorizontal="true"
    android:layout_marginEnd="5dp"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="5dp"
    android:layout_marginStart="5dp"
    android:src="@drawable/soccer_player"
    app:civ_border_color="@color/colorAccent"
    app:civ_border_width="2dp"/>

<android.support.v7.widget.CardView
    android:id="@+id/card"
    android:layout_width="400dp"
    android:layout_height="150dp"
    android:layout_marginTop="10dp">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/bg_card_review">

        <TextView
            android:id="@+id/tv_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Nije lose"
            android:textColor="@android:color/white"
            android:textSize="16sp"
            android:typeface="sans"/>

    </RelativeLayout>

</android.support.v7.widget.CardView>

Upvotes: 3

Views: 2712

Answers (1)

Muhannad Fakhouri
Muhannad Fakhouri

Reputation: 1544

You need to give a higher elevation for your ImageView. Try the following for example...

ViewCompat.setElevation(findViewById(R.id.iv_profile),yourCardView.getElevation() * 2);

Upvotes: 6

Related Questions