Background
Popups can be anchored to views, but the Toast is missing this API.
What I'd like to know, is how to correctly position a toast near a view (suppose prefer to put below if on upper half of screen, and above if on bottom half), so that they won't overlap each other, no matter the position&size of the view (unless really impossible because the view takes too much space, of course).
The problem
I'm aware there are various questions to this question, but all set the toast to be shown below the view, or manually set its position, without regard to the size of both of them.
What I've found
Currently I've found the next solutions:
- here, it doesn't take the size of the toast into consideration
- here, it lets you set the position of the toast manually, so they can still overlap each other.
It could be, however, that the toast that appears from long clicking an action item is anchored to the action item's view, but I didn't find out how it works there.
I've also tried many libraries from Android-Arsenal website, but all of them are either for styling the toasts, or make things that aren't toasts and sometimes don't even work well.
The question
Is there a generic way to use the same method used for Popups, on Toasts, so that it will be anchored to a view, without overlapping it?