Custom view height is cut on Android 24
Hey,
I have an issue on a Nvidia Shield K1 (Android 7.0). The height of a custom view is cut, when the anchor point is on the very top or very bottom of the screen.
On my phones / 10" tablet I don't have this problem.
I debugged this:
mPopupWindow.showAtLocation(mRootView, Gravity.NO_GRAVITY, mRootView.getWidth(), mRootView.getHeight());
The mRootView of my button is the Toplevel Window.
It is called with height = 1920, width = 1200
Which isn't the center position of the button?
I personally think we need something like this:
int pos[] = new int[2];
view.getLocationOnScreen(pos); // or this getLocationInWindow()
popupWindow.showAtLocation(view.getRootView(), Gravity.NO_GRAVITY, pos[0], pos[1]);
The initial position set to showAtLocation is fake, because the final position is calculated later with the arrow position. See this line.
Can you send a picture or screenshot of this problem?
Thx for pointing me to the calculation function. I'll try hunting the bug ;)
It's somehow strange only on the Nvidia Shield K1 (7" / 2015 / 7.0) there is this problem.
I'll send you a merge request or a sample project if I can't find the issue.
Thx!
@egandro I think I found the problem, but not the solution yet.
On Android 24, apparently, PopupWindow changed behavior when it did not fit the screen. In previous versions the PopupWindow position was adjusted automatically, without changing the size.
See on Android 23 (position adjusted):
But, on Android 24 the size is adjusted automatically:
I will work to find a solution, but suggestions are welcome 😄
Hey!
I got a hint from a friend.
It might be this flag:
https://developer.android.com/reference/android/widget/PopupWindow.html#attr_android:overlapAnchor
Can you give it a try?
Thx.
In my tests overlapAnchor did not work. But I found the source for this behavior, it's the property setClippingEnabled.
Setting setClippingEnabled(false) allows PopupWindow to override the screen boundary. See a example:
But if the PopupWindow stays outside the screen, it can be hidden.
Researching a little, I saw that the behavior of PopupWindow was changed on Android 24 and 25, but I'm not sure that this will change in the future.
- https://stackoverflow.com/questions/39673099/android-nougat-popupwindow-showasdropdown-gravity-not-working
- https://stackoverflow.com/questions/41973893/android-nougat-7-1-1-showatlocation-gravity-not-working
I've created a test branch (https://github.com/douglasjunior/android-simple-tooltip/commit/632b0289eb3a2943ff3bf49cb0271473186f560a), if you'd like to check it out.
dependencies {
// ...
compile ('com.github.douglasjunior:android-simple-tooltip:issue-40-SNAPSHOT') {
changing = true // Gradle will then check for updates every 24 hours
}
}
Thx man! I'll give it a try. In a view minutes.

Have a look. It still hast the issue on the K1 :(
Yes, the only solution I think is calculating the position manually.
I have an idea ;)
You can take the calculation algorithm from <24 and put it in your code.
Check the license if this is ok. But that would fix it 100%
It's not that simple, I'll keep thinking about a solution.
One suggestion, your Tooltip has a lot of information, it was not designed to be so big.
Would not it be better to display this layout in a Dialog? Or a tooltip centered on the screen?
I experimented with this a lot:
- Context Menu
- Dialog
- Adding more buttons to the Listview Row
- Adding multiple checkboxes to the Listview Row
My designer came up with the Popup solution as wie have it in the android simple tooltip.
The user experience is very very cool - it's consumes less space - and despite having the same amount of clicks - the users love the tooltip style as it is fast and integrates fluently in the workflow.
The dialog or the (default) context menu is a lot of slower and the user has to move the finger for a 20% longer distance ;)
You might have a look at the bottom of this page. This is (ugly) Javascript - but it's the algorithm to place a content menu depending on a pivot point:
https://stackoverflow.com/questions/15795253/positioning-context-menu
Check this on jsfiddle:
http://jsfiddle.net/AkshayBandivadekar/zakn7Lwb/14/
You can apply code on SimpleToolTip.java
At Line 38x :
private final ViewTreeObserver.OnGlobalLayoutListener mLocationLayoutListener
Before call update PopupWindow
mPopupWindow.update((int) location.x, (int) location.y, mPopupWindow.getWidth(), mPopupWindow.getHeight());
Apply this
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
int popupHeight = mPopupWindow.getContentView().getMeasuredHeight();
int endOfPopupY = popupHeight + (int) location.y;
if (endOfPopupY > getScreenHeight()) {
location.y = (getScreenHeight() - popupHeight);
}
}
@egandro @douglasjunior
Thanks @ThanawatMas , I'll look soon.