Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

124
Vistas
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 Respuestas
Responde la pregunta

0

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

over 4 years ago · Santiago Trujillo Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda