Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Positioning Issue: Tip Window appear to be more bottom on Android 11 #150

Open
samuelchou opened this issue Dec 21, 2020 · 6 comments
Open

Comments

@samuelchou
Copy link

Run the demo app on Google Pixel 5(Android 11) and you will see what similar to below. The ToolTip position seems to be more "bottom" than expected.

device-2020-12-21-150319

I'm sure that is not related to night theme, and not even related to gravity.

device-2020-12-21-151245

I don't know if this is related to Pixel (5) or Android 11, though.

@samuelchou
Copy link
Author

using AVD Pixel 3a API 30 x86 can cause similar problem.

device-2020-12-21-154752

@samuelchou
Copy link
Author

Android 8 and Android 10 cannot re-produce the issue, no matter what device it is. I guess the problem comes along with Android 11 (API 30)

@samuelchou samuelchou changed the title Positioning Issue: Tip Window appear to be more bottom on Google Pixel 5 / Android 11 Positioning Issue: Tip Window appear to be more bottom on Android 11 Dec 21, 2020
@amarilindra
Copy link

Facing the same issue on Google Pixel 2 XL (Android 11)

Found any solution @samuelchou ?

@SeanBlahovici
Copy link

So I banged my head against this issue, it seems to only be happening on Android 11 (not on Android 12).

Looks like you need to subtract the status bar height to get it aligned correctly.

val tooltip = Tooltip.Builder(context).anchor(this, 0, determineYOffset(context), true)

private fun determineYOffset(context: Context): Int =
          if (Build.VERSION.SDK_INT == Build.VERSION_CODES.R)
              -((context as? MainActivity)?.statusBarHeight ?: 0)
	else
              0

@zarsky
Copy link

zarsky commented Aug 18, 2021

Also, it looks like if the device has a notch/cut out, you need to compensate for its height as well. Based on the example above:

private fun determineYOffset(context: Context): Int =
    if (Build.VERSION.SDK_INT == Build.VERSION_CODES.R) {
        val activity = context as? MainActivity
        val statusBarHeight = activity?.statusBarHeight ?: 0
        val cutoutHeight = activity?.window?.decorView?.rootWindowInsets?.displayCutout?.safeInsetTop ?: 0
        cutoutHeight - statusBarHeight
    } else {
        0
    }

@ankuratdunzo
Copy link

@zarsky When I tested out your method on a device with a notch the cutoutHeight was equal to statusBarHeight which made yOffset 0 again. Can you specify for which case you needed cutoutHeight as well?
Also, I got statusBarHeight using the following method.

val metrics: WindowMetrics = activity.windowManager.currentWindowMetrics
val insets = metrics.windowInsets.getInsets(WindowInsets.Type.statusBars())
val statusBarHeight = insets.top

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants