问题描述
有每当文本设置为实在是太长了,我想重新设置一些preSET值的的TextView
有一定规模和。
There is a TextView
of a certain size and whenever text set to it is too long I'd like to re-set it to some preset value.
要做到这一点,我重写 onMeasure
并调用的setText
。然而,这并不影响的TextView
内容。
To accomplish this I am overriding onMeasure
and calling setText
. However this does not affect the TextView
contents.
我在想什么?
编辑:如果你认为它应该在一个完全不同的方式来完成 - 请随时提出
if you think that it should be done in a completely different way - please feel free to suggest
推荐答案
onMeasure()
在布局阶段通常被称为。此外,据我所知 onMeasure()
是您的有来衡量你的看法。它接收2值,它们的视图的父其可以是恒定的大小。
onMeasure()
is usually called during layout phase. Besides as far as I know onMeasure()
is where YOU have to measure your view. It receives 2 values which are the size of the parent of your view which may be constant.
你为什么不只是检查你设置文本的长度,如果它太长时间只使用默认取代它?
Why don't you just check the length of the text you're setting and if it's too long just replace it with your default one?
这篇关于为什么要设置从onMeasure文字不影响的TextView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!