Custom Layout that rounds the corners of its content

后端 未结 7 2059
北海茫月
北海茫月 2020-11-29 04:08

I would like to create a generic ViewGroup which can then be reused in XML layouts to round the corners of anything that is put into it.

For some reason canvas

7条回答
  •  旧巷少年郎
    2020-11-29 04:36

    Don't forget to ask for onDraw to be called with setWillNotDraw(false); and set a value to mRadius then just do something like that :

    @Override
    protected void onDraw(Canvas canvas) {
        mPath.reset();
        mRect.set(0, 0, canvas.getWidth(), canvas.getHeight());
        mPath.addRoundRect(mRect, mRadius, mRadius, Direction.CCW);
        mPath.close();
        canvas.clipPath(mPath);
    }
    

提交回复
热议问题