Android 10 tooltip lagging issue
Hi everybody. On Android 10 I have problem with lagging tooltip. On Android 9 and lower versions all works perfect. Do you have any idea how to fix this problem. @ViHtarb
Android 10 (picture preview)
Android 9 (picture preview)

Hi. Thanks for report. I know about this bug and trying to fix it but i have no idea how to do this exactly
Hmm, maybe is problem in "Gravity". In Android 9 is different rendering than in android 10. In Android 9 you need to wait few milliseconds more than in Android 10 to show tooltip.
Hi @ViHtarb do you have any idea now why this happen ? Did you find any similar issues on stackoverflow or any other site like medium, etc. ?
@MarioCroSite Hi, now i`m busy on work - we are making release. Sorry but i can't fix it soon. I think it's trouble with updating PopupWindow position on android 10.
@MarioCroSite it looks like PopupWindow can't update position while playing enterAnimation
Can you remove animation and make new snapshot ?
@MarioCroSite I can but this is not a solution to the problem
Can you maybe put here little snippet code what we need to change for workaround solution. @ViHtarb
@MarioCroSite As temporary fix for android 10 the tooltips will use showAtLocation method instead of showAsDropDown it`s prevent using animations. Fix will be available in alpha06 snapshot
@MarioCroSite done
Thanks @ViHtarb :)
I got a little insight on this bug. Usage of addOnGlobalLayoutListener is a little bit wrong, because it's called after a while, when popup is already shown. So my proposition would be to measure and calculate things before updating popup, rather than rely on onGlobalLayout.
Brief solution just for popup(without arrow for now) would be:
override fun show() {
if (!isShowing) {
// content.viewTreeObserver.addOnGlobalLayoutListener(locationLayoutListener)
anchor.addOnAttachStateChangeListener(onAttachStateChangeListener)
anchor.post {
if (anchor.isShown) {
val location = calculateLocation()
popupWindow.showAsDropDown(anchor)
popupWindow.isClippingEnabled = true
popupWindow.update(
location.x.toInt(),
location.y.toInt(),
content.measuredWidth,
content.measuredHeight
)
}
}
}
}
private fun calculateLocation(): PointF {
content.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED)
val location = PointF()
val anchorRect = calculateRectInWindow(anchor)
val anchorCenter = PointF(anchorRect.centerX(), anchorRect.centerY())
when (gravity) {
Gravity.LEFT -> {
location.x = anchorRect.left - content.measuredWidth - margin
location.y = anchorCenter.y - content.measuredHeight / 2f
}
Gravity.RIGHT -> {
location.x = anchorRect.right + margin
location.y = anchorCenter.y - content.measuredHeight / 2f
}
Gravity.TOP -> {
location.x = anchorCenter.x - content.measuredWidth / 2f
location.y = anchorRect.top - content.measuredHeight - margin
}
Gravity.BOTTOM -> {
location.x = anchorCenter.x - content.measuredWidth / 2f
location.y = anchorRect.bottom + margin
}
}
return location
}