Approximating “height” of layout when contains TextView

主宰稳场 提交于 2019-12-11 19:12:40

问题


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.



来源:https://stackoverflow.com/questions/55133937/approximating-height-of-layout-when-contains-textview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!