我想计算仅包含 TextView
作为 TextView 文本大小
的结果的行(或布局)高度(在 DP 中)何时使用默认行距?
IE。对于这种布局:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/minRow1col1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:textIsSelectable="false"
android:textSize="11dp" />
</LinearLayout>
布局/行高是多少? (任何公式?我不需要运行时的值)
谢谢!
最佳答案
我不知道这是否对你们有帮助,但我的解决方案是让一行的高度独立于布局的高度,只需采用这样的字体指标:
myTextView.getPaint().getFontMetrics().bottom - myTextView.getPaint().getFontMetrics().top)
有了这个,您将获得行高,对我来说,它适用于所有单词(有一些字符,如“g”或“j”占用一些底部空间,所谓的“descender”等)。
关于android - 如何在Android中计算包含具有特定高度的TextView的行高?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20247629/