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.
Create custom Layout with non-rectangle views and set clickListener for overlapping views in android
Asked
Active
Viewed 311 times
1
-
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 Answers
0
Here is one way that this may work:
- Use a rectangular
ImageView
for each shape. Make sure each shape is clickable. - Shape images will have a transparent portion where they fit together.
- Use
FrameLayout
or some similar layout that will allow overlapping ofView
s. You will have to work with how eachView
overlaps. - 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!