Android CardView remove padding

后端 未结 4 1160
走了就别回头了
走了就别回头了 2020-12-02 22:39

how do I get rid of this strange padding in the layout below:

\"enter

         


        
4条回答
  •  半阙折子戏
    2020-12-02 22:59

    UDPATE

    Well, seems there is a much easier way to do it, without guessing the padding and all:

    card_view:cardPreventCornerOverlap="false"
    

    or using java:

    cardView.setPreventCornerOverlap(false)
    

    You can read all about it here.

    ORIGINAL ANSWER

    It is an intentional padding to avoid content from bleeding off the rounded corner of the card in pre lollipop versions (since clipping is not available). If you want to get rid of it all together you may use a negative padding in pre-lollipop versions for the contentPadding attribute of the CardView such as:

    card_view:contentPadding="-8dp"
    

    or using java:

    int padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, getResources().getDisplayMetrics());
    cardView.setContentPadding(-padding,-padding,-padding,-padding);
    

    I'm not particularly sure which value will work seamlessly, you'll need to experiment and see for yourself.

提交回复
热议问题