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>
Add this to your MaterialCardView xml file
android:outlineProvider="none"
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/
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With