Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

115
Views
How do I detect the user-set screen zoom level in kotlin

I'm trying to find a way in Kotlin to detect the level of display zoom a user has set on their device. I currently have two image buttons with labels off to one side sitting side by side in a LinearLayout. The labels wrap mid-word if the display zoom is set past a certain threshold. What I'd like to do is detect the zoom level (or whatever it's called) and stack them vertically if the text is over a certain size so users with less than ideal eyesight can read them properly. Is this possible in Kotlin?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

DisplayMetrics.DENSITY_DEVICE_STABLE exists specifically for this purpose. Compare that to your current densityDpi.

over 4 years ago · Santiago Trujillo Report

0

I suggest you use a FlexboxLayout which kind of does what you're welling to achieve here.

However if you insist on using a LinearLayout and invert it's direction depending on weather your text fits there or not, you can use a BoringLayout which helps you to calculate the required width to draw a certain text e.g. the following code tells how much space SomeText requires to get drawn using a paint with the textSize=20 SP. So depending on this value you can decide how to set the orientation of your LinearLayout

val paint = TextPaint().apply {
            textSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 20f, context.resources.displayMetrics)
        }
BoringLayout.getDesiredWidth("SomeText", paint)
over 4 years ago · Santiago Trujillo Report

0

I was able to find the values I needed in the configuration namespace. There are two user settings that are effecting the layout, Font Scale and Display Zoom, both of which can be set independently from one another.

val config = resources.configuration
val fontScale = config.fontScale
val screenWidth = config.screenWidthDp
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!