When trying to get the height of a Android device, make sure you do it in an pixel density independent way:
correct way to get height:
valdisplayMetrics=Resources.getSystem().displayMetricsvalheightPixels=displayMetrics.heightPixels//exact physical pixel amount(different on certain devices)valdensity=displayMetrics.density//density multipliervalpixelDensityIndependentHeight=heightPixels/density
wrong way to get height:
valheight=Resources.getSystem().displayMetrics.heightPixels//as previously mentioned, this height will change depending on the // device's pixel density and it can really mess up your UI
Why does this matter?
I have created THIS UI FEATURE which relies heavily on my app being able to understand the height of the device and dividing it into 3 sections. If I don't use the height in a pixel density independent way(unfortunately I did this) the UI will look different on different devices. Which obviously is not ideal
So to summarize, make sure you are conscious of pixel densities in your UI
Conclusion
Thank you for taking the time out of your day to read this blog post of mine. If you have any questions or concerns please comment below or reach out to me on Twitter.
We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.
Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.
Top comments (0)