简体   繁体   中英

Custom SHAPED Layout with clipping bounds

Well yes, I couldn't find anything that could help me for real so far... from StackOverflow to libraries and other things...

I need a custom shaped FrameLayout that is clipping his child inside of it. The problem is that I want this shape to be really custom, for example shirt / hat / etc..

So, somehow I want to clip child of FrameLayout inside the shirt let's say. I found something related to onDraw method, but I didn't find a way of getting pathData of a vector . . .

Any clear idea about how I could sort this up ( if possible ) is welcomed !

Thank you

You can use clip path. Your code can look something like:

private void updatePath() {
    path = new Path();
    // Draw your special shape...
}

@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
    canvas.clipPath(path);
    return super.drawChild(canvas, child, drawingTime);
}

@Override
protected void onDraw(Canvas canvas) {
    canvas.clipPath(path);
    super.onDraw(canvas);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM