Search code examples
androidandroid-linearlayoutnine-patchandroid-framelayoutcustom-view

Define layout content area


enter image description here

I want to define the contentArea of a Frame/Linear/Relative layout so that when I do layout.addView(view); it only added within the boundries and the rest of the view is clipped away. Like the picture of shirt, if I want to define the boundries of shirt to be the area of content...how can I do that. Any suggestions/help? Thanks

PS: cannot do that in 9-patch (right and bottom) as it only defines in rectangular shape, in this case shape can be anything like that of a shirt. Want to omit the white/transparent part from the contentArea.


Solution

  • try the below code :- Just in case someone is trying to solve same problem, there is a better solution: Bitmap.createBitmap(Bitmap, int x, int y, int width, int height). For example, if you need to crop 10 pixels from each side of a bitmap then use this:

    Bitmap croppedBitmap = Bitmap.createBitmap(originalBitmap, 10, 10, originalBitmap.get