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

查看:197
本文介绍了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.

这是我们正在做的:

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

以前有人看过吗?

推荐答案

此处的区别在于,在setTextSize(int size)方法中,单位类型默认为"sp"或缩放的像素".对于每个屏幕密度(ldpi,mdpi,hdpi),此值都将是不同的像素尺寸.

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 unit, float size)指定单位类型.可以在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天全站免登陆