CardView ignores android: clipChildren = "false"

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

However, I cannot get it to work with CardView. ImageView will be cropped and will not overlap 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> 
+7
android margin android-cardview
source share
2 answers

Well, it looks like this is only a problem with Android 5+, the solution is to install

 cardView.setClipToOutline(false); 

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

+5
source share

wrap it in LinearLayout with the LinearLayout parameter

 <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> 
+1
source share

All Articles