Strange issue with android:ellipsize=“end”

前端 未结 5 2163
野的像风
野的像风 2021-02-20 14:53

I am using android:ellipsize=\"end\" in android xml file, & surprisingly I am not getting the layout that I want, the 3 dots(...) are showing but after that

5条回答
  •  死守一世寂寞
    2021-02-20 15:33

    Finally found what was causing this issue in my app!!

    While RuAware's answer led me on the right path, I found that it didn't fix the problem for all of my text blocks. Given that it worked for some, I felt it was clearly due to some malicious character. So I went through one broken text block and just started removing characters until it stopped breaking.

    It turns out it was the new line character '\n' that was causing it. Even if the new line was after the ellipsize, the new line character was [inconsistently] causing this problem as long as it was somewhere within the string.

    The issue is solved by doing something similar to the following before setting the text to your view:

    text = text.replace('\n',' ');
    

提交回复
热议问题