Last active
September 4, 2019 12:37
-
-
Save zorroyueng/c1f6c6c2912ee67aa9660430291e5280 to your computer and use it in GitHub Desktop.
Clip a layout with round conner
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 创建一个圆角的Layout, 且不影响该Layout的background | |
| */ | |
| 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); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment