Approximating “height” of layout when contains Tex

2019-08-30 04:05发布

问题:

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 TextViews 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.