Is it possible?

Task: there are images of different sizes, on the image you need to add text to the entire image in height and proportionally in width. It is necessary that the font itself was selected depending on the size of the image.

  • 2
    for example, group ImageView and TextView into a FrameLayout container, then use autosizing in TextView - pavlofff

1 answer 1

There are several options for measuring the height of the image (transferring it to sp - optional) and setting or setting such a parameter in the markup:

Option 1:

 int imageSize = imageView.getMeasuredHeight() float sp = imageSize / getResources().getDisplayMetrics().scaledDensity; textView.setTextSize(sp); 

Option 2 :

 android:autoSizeTextType="uniform" 

Try what suits you best or look for something else to your taste.

  • one
    in the first version, why do we get imageSize, if it is not used in the example and where did the px come from? - pavlofff
  • one
    @pavlofff, I did not correctly read the question. I thought that the pictures will be added dynamically. In principle, such an implementation takes place. - Valeriy