Skip to content Skip to sidebar Skip to footer

Android Cliprect Not Clipping As Expected

I would like to clip the string when it hits the icon. This would mean that the string would be clipped when it hit iconSize + iconMargin. This is the code I have in onDraw, which

Solution 1:

canvas.clipRect takes four parameter as input to represent a rectangle in canvas coordinates.

  • left = X coordinate of rectangles left corner
  • top = Y coordinate of rectangles top corner
  • right = X coordinate of rectangles right corner
  • bottom = Y coordinate of rectangles bottom corner

The rect in your example has 0 as top and bottom corner Y coordinate and this results in a rectangle with 0 height. So change your code to something like this:

canvas.clipRect((itemIconSize + itemIconMargin).toInt() //left: right side of icon
, 0// top: top point of the view
, view.width// right: end of the View
, view.height// bottom: bottom of the View
)

Post a Comment for "Android Cliprect Not Clipping As Expected"