CardView忽略android:clipChildren ="false"

tym*_*ymm 9 android margin android-cardview

我想要一个包含ImageView的CardView,它与CardView的左边界重叠.我想通过给ImageView一个负余量来做到这一点.通过设置clipChildren ="false",这适用于所有其他布局(LinearLayout/RelativeLayout/FrameLayout).

但是我无法使用CardView.ImageView将被剪裁,并且不会与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>
Run Code Online (Sandbox Code Playgroud)

Kri*_*raj 8

好吧,这似乎只是Android 5+的问题,解决方案是设置

cardView.setClipToOutline(false);
Run Code Online (Sandbox Code Playgroud)

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

  • 不仅仅是5.0的问题,低版本也不起作用.该解决方案仅支持api级别21及以上.以下版本的解决方案是什么? (5认同)