TextView.setTextSize行为异常 - 如何动态地设置的TextView的文本大小不同势屏幕 [英] TextView.setTextSize behaves abnormally - How to set text size of textview dynamically for diffrent screens

查看:178
本文介绍了TextView.setTextSize行为异常 - 如何动态地设置的TextView的文本大小不同势屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

调用 TextView.setTextSize()的工作不正常。调用 setTextSize 之后,如果我们得到了一个 getTextSize 它返回一个更高的值,我们将其设置为更早。

Calling TextView.setTextSize() is working abnormally. Right after the call to setTextSize if we get a getTextSize its returning a much higher value that what we set it to earlier.

下面就是我们正在做的:

Here's what we're doing:

zoomControl.setOnZoomInClickListener(new OnClickListener() {
    public void onClick(View view) {
        float size = mViewShabad.getTextSize() + 1;
        textView.setTextSize(size);
    }
});

有没有人见过这个?

Has anyone seen this before?

推荐答案

这里的区别是,在 setTextSize(INT尺寸)方法,默认情况下,单位类型是SP或缩放像素。该值将是为每个屏幕像素密度(LDPI,MDPI,华电国际)不同的像素尺寸。

The difference here is that in the setTextSize(int size) method, the unit type by default is "sp" or "scaled pixels". This value will be a different pixel dimension for each screen density (ldpi, mdpi, hdpi).

getTextSize(),在另一方面,返回文本的实际像素尺寸。

getTextSize(), on the other hand, returns the actual pixel dimensions of the text.

您可以使用 setTextSize(INT单元,浮点大小)来指定单位类型。这个常量的值可以在类的TypedValue中找到,但其中一些是:

You can use setTextSize(int unit, float size) to specify a unit type. The constant values for this can be found in the TypedValue class, but some of them are:

TypedValue.COMPLEX_UNIT_PX   //Pixels

TypedValue.COMPLEX_UNIT_SP   //Scaled Pixels

TypedValue.COMPLEX_UNIT_DIP  //Device Independent Pixels

这篇关于TextView.setTextSize行为异常 - 如何动态地设置的TextView的文本大小不同势屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆