0

I'm making a function that sends Images Views Resource's size. The idea is to use this function in all the project for all the Image Views.

I need to send a height and width, so I've tried:

val widht =
binding.image.widht

val height = 
binding.image.height

The problem is, that somethimes I got "0" and, othertimes (when the images have "match parent" or "wrap content") got null.

Is there a function to get those values?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
Nicote Ool
  • 121
  • 8

1 Answers1

0

It depends on where and when you do this. If you call it before the view you want to measure is drawn/created you will get 0. To make sure that you take measurements after the view is done, you need to do something like this (in java, hope you can figure out kotlin):

imageView.post(() -> {
            /* Run your measuring code here */
        });
Vanheden
  • 582
  • 5
  • 14