本文介绍了在视图中缩放文本以适应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不相信这存在,但想仔细检查一下.我想设置 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
.当文本被省略时,这个回调由 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
while (mText != TextUtils.ellipsize(mText, textPaint, other params)) {
textpaint.setTextSize(textpaint.getTextSize() - 1);
}
这篇关于在视图中缩放文本以适应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!