Android: can I create a view/canvas that is not rectangular, but e.g. round?

I have a view that is round and hovering above (-> in z-axis direction coming out of the screen) the main content. When the someone taps the screen I want either the main content to be selected or the view hovering above, when it covers the main view.

So far that works perfectly. I have a round shaped item on a transparent canvas. Meaning you can see everything of the background that is outside of that circle. However, you cannot select it, because it is still the hovering canvas, just with a transparent paint.

  • Custom camera recorder preview get stretched when MediaRecorder.start() gets called
  • How do I reduce the line spacing between text in my Android layout?
  • Change MediaController position on rotation
  • Material Design progressdialog
  • VFY: unable to find class referenced in signature
  • is there any diff @null Vs #00000000
  • Now I’m wondering, to solve this issue, if it is possible to make the view/canvas itself round shaped?


    Update

    I added an image for better explanation what I try to achieve.
    alt text

    Related posts:

    Does the Google Maps Android API Utility Cluster Manager have a minimum number of markers before it ...
    How to use Android MediaCodec encode Camera data(YUV420sp)
    Get value (String) of ArrayList<ArrayList<String>>(); in Java
    How to use git branch with Android Studio
    Can I gain some efficiency by declaring appropriate members “static” in Android ...
    Using a rounded corners drawable
  • Android, gestures over clickable widgets
  • Modifying or Changing Min, Max and Displayed values for NumberPicker
  • Max size of an Android Application
  • Android autocomplete multiple textview lines in one result
  • Android OkHttp with Basic Authentication
  • android custom EditText UI
  • 3 Solutions collect form web for “Android: can I create a view/canvas that is not rectangular, but e.g. round?”

    As far as I know – it is impossible. I have checked the sources of View.java at git.kernel.org and it is based on Rect class – rects define position, size, regions to invalidate etc. (“The geometry of a view is that of a rectangle.” – from the comments in View.java)

    As for Canvas class – it is usually constructed over Bitmap or GL. Bitmap is definitely a rectange (a matrix), so canvas seems to represent a rectange too. If using GL a viewport is specified (which is a rectangle, too).

    It seems to be the most obvious way to check if the coordinates passed to your onTouch() method fit you region and return false if they don’t. Then the event will be passed to the View below and it should process the event.

    Probably not relevant to the original asker anymore, but for anyone who’s still looking, it looks like this will be added in L: https://developer.android.com/preview/material/views-shadows.html#clip. The View.setClipToOutline method allows you to clip a view to the shape of a rectanglular, circular, or round rectangular drawable.

    You need to specify an Android Selector to avoid the default hovering image.

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.