pt1*_*123 6 fonts android font-size textview
我无法在任何地方找到如何测量Textview中的getTextSize().从视觉测试看,它似乎不包括下降器,但似乎包括上升器.它似乎也不是从基线开始.
http://en.wikipedia.org/wiki/Descender
这是最接近它的提及,但谷歌的罗曼盖伊忽略了这个问题的一部分.
http://www.mail-archive.com/android-developers@googlegroups.com/msg08514.html
因为我需要这个,因为我正在使用Compound Drawables,我需要能够将drawable与不同设备上的文本对齐.
这是我用来测试复合可绘制圆形的代码,它接触边缘
tvData.setTextSize(TypedValue.COMPLEX_UNIT_PX, 100);
tvData.setText("agB5ãÂ");
int size = (int)tvData.getTextSize();
Drawable img = getResources().getDrawable(R.drawable.circle_white_full_72 ).mutate();
img.setBounds( 0 , 0 , size , size);
tvData.setCompoundDrawables( null, null, img, null );
Run Code Online (Sandbox Code Playgroud)
这是结果

你可以看到它似乎没有使用下降器和上升器.
这是可绘制的图像,如果其他人想要测试 http://i.imgur.com/Yhf8b.png
使用时将图像更改为文本大小的80%
int size = (int)tvData.getTextSize() *80/100;
Run Code Online (Sandbox Code Playgroud)
这是结果,图像转换在100%图像的顶部.也许setCompoundrawables正在做它自己的缩放

我尝试测量字体的中点和drawable,它是关闭的.这是一个突出显示它的图像
最后,我将可绘制的50像素移动到左侧,然后测量输出,它是字体文本基线到基线的高度的一半,因为setTextSize设置为100px.
Android必须使用其他一些布局来缩放和定位复合drawable.也许我应该为此创建另一个问题.这是一个突出基线到基线的图像.
从一些光测试来看,它似乎是从上升到下降(文本大小 = 下降 - 上升)。使用 TextPaint 进行了一些调试来验证,更具体一点,我做了:
Paint.FontMetricsInt metrics;
for(int i = 1; i < 100; i++) {
mTextPaint.setTextSize(i);
metrics = mTextPaint.getFontMetricsInt();
if((metrics.descent - metrics.ascent) != i) Log.v("type", "Not equal");
}
Run Code Online (Sandbox Code Playgroud)
对于每个值来说都是如此。
| 归档时间: |
|
| 查看次数: |
2807 次 |
| 最近记录: |