作者:mobiledu2502875993 | 来源:互联网 | 2023-06-11 17:40
IhaveTextViewwithwidthaswrapcontent.InthisTextViewIsettext,buttextisnotofthesame
I have TextView
with width as wrap content
. In this TextView
I set text, but text is not of the same length every time. When text is very long I use single line true and ellipsize
: end. But now I have a problem. I want to set Visibility of other layout but that depends on the length my text. If text is too long to fit in the screen I want to setVisible true, but when text is short and when I don't need ellipsize, I want to set visibility false. So I need to check status of my TextView. When its ellipsize I want to setVisible
true, when its not setVisible
false. How I can do that. This is what I got:
我有TextView,宽度为wrap内容。在这个TextView中,我设置了文本,但是文本的长度不是每次都相同。当文本很长时,我使用单行true和椭圆:end。但现在我有一个问题。我想要设置其他布局的可见性,但这取决于文本的长度。如果文本太长,不能适应屏幕,我想设置为true,但是当文本很短,当我不需要椭圆时,我想设置可见性错误。所以我需要检查我的TextView的状态。当它的椭圆大小我想要setVisible true,当它不是setVisible false。我怎么能做到。这就是我得到的:
tvAle.post(new Runnable() {
@Override
public void run() {
int lineCount = tvAle.getLineCount();
Paint paint = new Paint();
paint.setTextSize(tvAle.getTextSize());
final float size = paint.measureText(tvAle.getText().toString());
Log.v("a", ""+size+" "+tvAle.getWidth());
if ((int)size > (tvAle.getWidth()+10)) {
allergiesLayout.setVisibility(View.VISIBLE);
}
else
allergiesLayout.setVisibility(View.GONE);
}
but this solution doesn't work.
但这个办法行不通。
3 个解决方案