1

Is there any way to make following Layout in Android..? If yes please suggest how to make and how to set clickListener's of overlapping areas of Views...? i.e View 2's area overlaps 1's area and View 3's area overlaps 2'sand 4's area and so on others views overlaps..? If there is any android library to make non-rectangle buttons/Views also suggest.. Thanks.

Custom Layout

Engr Zee
  • 175
  • 1
  • 1
  • 9
  • The above answer is using depreciated methods, [See this running example](https://stackoverflow.com/a/58085531/6086086) – Asad Sep 24 '19 at 17:36

1 Answers1

0

Here is one way that this may work:

  1. Use a rectangular ImageView for each shape. Make sure each shape is clickable.
  2. Shape images will have a transparent portion where they fit together.
  3. Use FrameLayout or some similar layout that will allow overlapping of Views. You will have to work with how each View overlaps.
  4. Make the transparent portions un-clickable. See this Stack Overflow question and its accepted answer regarding one way to do this. (N.B. I have not tested this.) You should be able to work it so that clicks propagate downward to an underlying ImageView when a transparent region is clicked.

An alternate way would be just to have two views (left and right) and implement a View.OnTouchListener to determine where the click occurs by looking at adjoining pixels: their color and placement.

Good luck!

Community
  • 1
  • 1
Cheticamp
  • 61,413
  • 10
  • 78
  • 131