aunkang

createCornersPath

Sep 21st, 2021
772
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. private Path createCornersPath(int left, int top, int right, int bottom, int cornerWidth){
  2.         Path path = new Path();
  3.  
  4.         int cornerRadius = 40;
  5.  
  6.         //path.moveTo(left, top + cornerWidth);
  7.         //path.lineTo(left, top);
  8.         //path.lineTo(left + cornerWidth, top);
  9.  
  10.         //Top-Left
  11.         path.moveTo(left, (top + cornerRadius));
  12.         path.arcTo(
  13.                 new RectF(left, top, left + cornerRadius, top + cornerRadius),
  14.                 180f,
  15.                 90f,
  16.                 true
  17.         );
  18.  
  19.         path.moveTo(left + (cornerRadius / 2f), top);
  20.         path.lineTo(left + (cornerRadius / 2f) + cornerWidth, top);
  21.  
  22.         path.moveTo(left, top + (cornerRadius / 2f));
  23.         path.lineTo(left, top + (cornerRadius / 2f) + cornerWidth);
  24.  
  25.         //path.moveTo(right - cornerWidth, top);
  26.         //path.lineTo(right, top);
  27.         //path.lineTo(right , top + cornerWidth);
  28.  
  29.         //Top-Right
  30.         path.moveTo(right - cornerRadius, top);
  31.         path.arcTo(
  32.                 new RectF(right - cornerRadius, top, right, top + cornerRadius),
  33.                 270f,
  34.                 90f,
  35.                 true
  36.         );
  37.  
  38.         path.moveTo(right - (cornerRadius / 2f), top);
  39.         path.lineTo(right - (cornerRadius / 2f) - cornerWidth, top);
  40.  
  41.         path.moveTo(right, top + (cornerRadius / 2f));
  42.         path.lineTo(right, top + (cornerRadius / 2f) + cornerWidth);
  43.  
  44.         //path.moveTo(left, bottom - cornerWidth);
  45.         //path.lineTo(left, bottom);
  46.         //path.lineTo(left + cornerWidth, bottom);
  47.  
  48.         //Bottom-Left
  49.         path.moveTo(left, bottom - cornerRadius);
  50.         path.arcTo(
  51.                 new RectF(left, bottom - cornerRadius, left + cornerRadius, bottom),
  52.                 90f,
  53.                 90f,
  54.                 true
  55.         );
  56.  
  57.         path.moveTo(left + (cornerRadius / 2f), bottom);
  58.         path.lineTo(left + (cornerRadius / 2f) + cornerWidth, bottom);
  59.  
  60.         path.moveTo(left, bottom - (cornerRadius / 2f));
  61.         path.lineTo(left, bottom - (cornerRadius / 2f) - cornerWidth);
  62.  
  63.         //path.moveTo(right - cornerWidth, bottom);
  64.         //path.lineTo(right, bottom);
  65.         //path.lineTo(right, bottom - cornerWidth);
  66.  
  67.         //Bottom Right
  68.         path.moveTo(left, bottom - cornerRadius);
  69.         path.arcTo(
  70.                 new RectF(right - cornerRadius, bottom - cornerRadius, right, bottom),
  71.                 0f,
  72.                 90f,
  73.                 true
  74.         );
  75.  
  76.         path.moveTo(right - (cornerRadius / 2f), bottom);
  77.         path.lineTo(right - (cornerRadius / 2f) - cornerWidth, bottom);
  78.  
  79.         path.moveTo(right, bottom - (cornerRadius / 2f));
  80.         path.lineTo(right, bottom - (cornerRadius / 2f) - cornerWidth);
  81.  
  82.         return path;
  83.     }
RAW Paste Data