Toast setGravity works on BareMetal but not on SVD

I was working on the second Challenge in this section and I want to display the result toast on top of the screen so it won’t overlap with the question answer toast.
However when I run it on SVD, the result percentage is still displayed exactly right where the normal toast is shown. I thought I messed with the code but apparently when I tested it again with my S9, it works just fine. Is this an SVD-related problem or is there anything else I need to know?
Plus there’s this other problem with SVD that I want to ask about. There is a short delay when the new toast comes out. It’s instantaneous on baremetal as far as I know.
Thank you for your clarification. That will help me a ton. I’m very new to Kotlin.

To make the context clear I will provide with my code:

if (answeredQuestionCount==questionBank.size) {
        var toast: Toast = Toast.makeText(this, "${correctAnswerCount/answeredQuestionCount.toDouble() * 100} %", Toast.LENGTH_LONG)
        toast.setGravity(Gravity.TOP, 85, 120)
        toast.show()
    }

And the screenshots on how it works:

@sythanh14 this might have been mentioned by someone else so forgive me if I’m repeating it but as per the android developer documentation setGravity() will not work for text toasts starting with Android R. I also think they recommend Snackbars over Toasts.

1 Like