How does one go about creating a View
that has boundaries with triangular perforations ?
I\'ve been using background drawables to achieve this so
You can draw a zigzag path in background of your view
Rect rectZigzag = new Rect();
private Path pathZigzag = new Path();
private Paint paintZigzag;
private void init(){
this.paintZigzag = new Paint();
this.paintZigzag.setColor(zigzagBackgroundColor);
this.paintZigzag.setStyle(Style.FILL);
}
private void drawZigzag() {
float left = rectZigzag.left;
float right = rectZigzag.right;
float top = rectZigzag.top;
float bottom = rectZigzag.bottom;
int width = (int) (right - left);
pathZigzag.moveTo(right, bottom);
pathZigzag.lineTo(right, top);
pathZigzag.lineTo(left, top);
pathZigzag.lineTo(left, bottom);
int h = zigzagHeight;
int seed = 2 * h;
int count = width / seed;
int diff = width - (seed * count);
int sideDiff = diff / 2;
float x = (float) (seed / 2);
float upHeight = bottom - h;
float downHeight = bottom;
for (int i = 0; i < count; i++) {
int startSeed = (i * seed) + sideDiff + (int) left;
int endSeed = startSeed + seed;
if (i == 0) {
startSeed = (int) left + sideDiff;
} else if (i == count - 1) {
endSeed = endSeed + sideDiff;
}
this.pathZigzag.lineTo(startSeed + x, upHeight);
this.pathZigzag.lineTo(endSeed, downHeight);
}
}
refrence