Android CardView remove padding

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

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

\"enter

         


        
4条回答
  •  清歌不尽
    2020-12-02 23:07

    Got the same problem and this worked for me.

    app:cardPreventCornerOverlap="false"
    

    For device with API < 21, I had to make a custom ImageView class, override the onDraw to draw the round corners.

    @Override
    protected void onDraw(Canvas canvas) {
        float radius = getContext().getResources().getDimension(R.dimen.card_corner_radius);
        Path path = new Path();
        RectF rect = new RectF(0, 0, this.getWidth(), this.getHeight());
        path.addRoundRect(rect, radius, radius, Path.Direction.CW);
        canvas.clipPath(path);
        super.onDraw(canvas);
    }
    

提交回复
热议问题