我正在创建一个小部件,我需要为其计算 minHeight
和 minWidth
。
现在,如果我有一个 TextView
,其宽度和高度为 wrap_content
,文本大小为 18sp
,我如何找到TextView
的 dp
大小是多少?
最佳答案
TextView tv;
int tvWidth = tv.getWidth();
int tvHeight = tv.getHeight();
float density = getResources().getDisplayMetrics().density;
float densityWidth = tvWidth / density;
float densityHeight = tvHeight / density;
如果我没理解错的话,它是给你的。
关于android - wrap_content 时 TextView 的 dp 大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11326174/