问题
I want to use this simple layout for items of list:
Note the right gray area (which I draw red rectangle on its border in below) must be a square:
So I have to approximate the height of layout. It must be simple, but the problem is that the text size of TextView
s is set by using sp
unit and height of layout must be set by dp
unit and I did not found a way for converting dp
and sp
in .xml
file. Also I do not want to create a CustomView
or change properties of layout at runtime. All things must be done in .xml
file. How I can approximate height of layout?
回答1:
See the TextSize is different from TextView's width and height. So Provide fixed width-height to all views in "dp". Fixed Text-Size in "sp" that fits perfectly inside TextView. P.S. -> test in a few devices/emulators to verify.
来源:https://stackoverflow.com/questions/55133937/approximating-height-of-layout-when-contains-textview