在视图缩放文本以适应? [英] Scale text in a view to fit?
本文介绍了在视图缩放文本以适应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不相信这一点的存在,但要仔细检查。我想设置一个TextView的文字大小等,这将符合规定的宽度,单行之内。例如:
I don't believe this exists, but wanted to double-check. I'd like to set a TextView's text size such that it would fit within a given width, single line. Example:
<LinearLayout
layout_width="100dip"
layout_height="50dip">
<TextView
layout_width="fill_parent"
layout_height="wrap_content"
textSize="fill"
text="fit me please!" />
</LinearLayout>
感谢
推荐答案
您可以使用 TextUtils.EllipsizeCallback
。当文字被ellipsized这个回调是由TextView中完成的。在这里,您可以设置文字的大小比当前更小。
You can use the TextUtils.EllipsizeCallback
. When the text gets ellipsized this callback is done by the textview. Here you can set text size smaller than the current.
编辑:,否则,您可以使用 TextUtils.ellipsize
这样
EDIT : Otherwise you can use TextUtils.ellipsize
this way
while (mText != TextUtils.ellipsize(mText, textPaint, other params)) {
textpaint.setTextSize(textpaint.getTextSize() - 1);
}
这篇关于在视图缩放文本以适应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文