I have 5 textviews, each textview has its own background and they are one next to the other, their sizes change depending on the amount of text that I put in them. I want to know if at any point they stop fitting because they reach the border of the parent. But not only that if they dont fit I want to b开发者_高级运维e able to add something like "click here to see more". So how do I detect how much space have they taken so far as I go adding the text to them? thanks
You can use TextUtils.ellipsize.
Maintain the actual text in a member. Call ellipsize with the text as parameter and set the returned text to the textview.
You can set a callback TextUtils.EllipsizeCallback
which will be called when the text gets ellipsized.
TextUtils.EllipsizeCallback ellipsizeCallback = new TextUtils.EllipsizeCallback(){
void ellipsized(int start, int end) {
// enable the `click here to see more` button.
}
}
...
CharSequence elipsizedText = ellipsize (mtext, mtxtpaint,
avail, TextUtils.TruncateAt.END ,
preserveLength, ellipsizeCallback);
tv.setText(mtext);
精彩评论