Skip to content

Instantly share code, notes, and snippets.

@zorroyueng
Last active September 4, 2019 12:37
Show Gist options
  • Save zorroyueng/c1f6c6c2912ee67aa9660430291e5280 to your computer and use it in GitHub Desktop.
Save zorroyueng/c1f6c6c2912ee67aa9660430291e5280 to your computer and use it in GitHub Desktop.

Revisions

  1. zorroyueng revised this gist Sep 4, 2019. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions RoundConnerViewGroup.java
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,6 @@
    /**
    * 创建一个圆角的Layout, 且不影响该Layout的background
    */
    public class RoundConnerViewGroup extends ViewGroup {

    private Path path;
  2. zorroyueng created this gist Sep 4, 2019.
    24 changes: 24 additions & 0 deletions RoundConnerViewGroup.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    public class RoundConnerViewGroup extends ViewGroup {

    private Path path;
    private static final CONNER_RADIUS = <whatever_you_want>;


    @Override
    protected void onSizeChanged(int width, int height, int oldWidth, int oldHeight) {
    super.onSizeChanged(width, height, oldWidth, oldHeight);

    float cornerRadius = CONNER_RADIUS;
    this.path = new Path();
    this.path.addRoundRect(new RectF(0, 0, width, height), cornerRadius, cornerRadius, Path.Direction.CW);
    }

    @Override
    protected void dispatchDraw(Canvas canvas) {
    if (this.path != null) {
    canvas.clipPath(this.path);
    }
    super.dispatchDraw(canvas);
    }

    }