Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CardView ignoring android:clipChildren="false"

I want to have a CardView which contains an ImageView which overlaps the left border of the CardView. I want to do this by giving the ImageView a negative margin. This works fine with all other layouts (LinearLayout/RelativeLayout/FrameLayout) by setting clipChildren="false".

However I can't get it to work with a CardView. The ImageView will be clipped and does not overlap the CardView.

<android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="15dp"
        android:clipChildren="false">
    <ImageView
           android:layout_marginLeft="-10dp"
           android:background="@drawable/some_picture"
           android:layout_width="50dp"
           android:layout_height="50dp"/>
</android.support.v7.widget.CardView>
like image 300
tymm Avatar asked Sep 02 '15 14:09

tymm


3 Answers

Add this to your MaterialCardView xml file

android:outlineProvider="none"
like image 163
Grey Lưu Avatar answered Nov 17 '22 20:11

Grey Lưu


Ok, this seems to be a problem only with Android 5+, the solution is to set

cardView.setClipToOutline(false);

Source - https://www.reddit.com/r/androiddev/comments/2tccge/cant_draw_outside_of_cardview_parent/

like image 26
Krishnaraj Avatar answered Nov 17 '22 20:11

Krishnaraj


wrap it in LinearLayout with param LinearLayout

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipChildren="false">

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

</LinearLayout>
like image 36
Dmitriy Avatar answered Nov 17 '22 22:11

Dmitriy