0

Question:

I have got an Activity used as a popup.

It's background is a shape with rounded corners.

But the items of it's content view don't fill out the shape. They are more likely inside of an invisible rectangle inside of the shape.

Can I somehow make them fill the shape and being cut when overlapping the corners?


Solution:

  1. Add this code to the view with the shape background:

view.setClipToOutline(true); --> clips the view view.setOutlineProvider(ViewOutlineProvider.BACKGROUND); --> tells the view to be clipped by the background(shape)

  1. If the paddings of the view are too big, just make them smaller so you can see an effect of the clipping
Cactusroot
  • 1,019
  • 3
  • 16

1 Answers1

1

Yes, it's possible to do this. It's called View Clipping.

Here is an existing question about clipping: Android View Clipping

You have 2 options:

1- Implement a custom View and override onDraw so you can perform the clipping manually. See here: https://stackoverflow.com/a/28206555/6007104

2- Use View.outlineProvider and View.clipToOutline. This is the easier option, but only available on SDK 21+. See here: https://stackoverflow.com/a/54202660/6007104

Luke Needham
  • 3,373
  • 1
  • 24
  • 41