Advertisement
Guest User

Untitled

a guest
Sep 15th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. /**
  2. * 创建一个圆角的Layout, 且不影响该Layout的background
  3. */
  4. public class RoundConnerViewGroup extends ViewGroup {
  5.  
  6. private Path path;
  7. private static final CONNER_RADIUS = <whatever_you_want>;
  8.  
  9.  
  10. @Override
  11. protected void onSizeChanged(int width, int height, int oldWidth, int oldHeight) {
  12. super.onSizeChanged(width, height, oldWidth, oldHeight);
  13.  
  14. float cornerRadius = CONNER_RADIUS;
  15. this.path = new Path();
  16. this.path.addRoundRect(new RectF(0, 0, width, height), cornerRadius, cornerRadius, Path.Direction.CW);
  17. }
  18.  
  19. @Override
  20. protected void dispatchDraw(Canvas canvas) {
  21. if (this.path != null) {
  22. canvas.clipPath(this.path);
  23. }
  24. super.dispatchDraw(canvas);
  25. }
  26.  
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement