tymm tymm - 5 months ago 108
Android Question

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>

Answer

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/