近似“高度"为0.包含TextView时的布局布局 [英] Approximating "height" of layout when contains TextView
问题描述
我想对列表项使用这种简单的布局:
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:
所以我必须近似布局的高度.它必须很简单,但是问题是TextView
s的文本大小是使用sp
单位设置的,而版面高度必须是dp
单位设置的,我没有找到转换dp
的方法和.xml
文件中的sp
.我也不想在运行时创建CustomView
或更改版式的属性.所有事情都必须在.xml
文件中完成.如何估算布局高度?
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?
推荐答案
请参见TextSize与TextView的宽度和高度不同. 因此,为"dp"中的所有视图提供固定的宽度-高度.修复了"sp"中的Text-Size,它完全适合TextView. P.S. ->在一些设备/仿真器中进行测试以进行验证.
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.
这篇关于近似“高度"为0.包含TextView时的布局布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!