如何“截断” android中textview内的文本根据方向?
我创建了一个简单的 java 函数来截断要在列表视图中显示的字符串。我正在显示新闻标题,其下方是新闻摘要。我希望有与下图相同的行为。目前,我正在将新闻标题截断为 45 个字符,然后在其末尾附加“...”。但是,当我将方向更改为横向时,标题可能会出现而不会被截断。我不认为下面的应用程序会截断新闻标题,但它将标题保留在一行中并自动“截断”。
如何在我的应用程序中实现此行为?
I created a simple java function to truncate a string to be displayed in my list view. I am displaying a news title and below this a news summary. I would like to have the same behavior as the image below. Currently, i am truncating the news title with 45 chars and then appending "..." at the end of it. However, when I change the orientation to landscape, the title could appear without being truncated. I dont think the app below truncates the news title, but it keeps the title in a single line and automatically "truncates".
How can I achieve this behavior in my app?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您不需要手动截断标题。 Android TextView 组件有 ellipsize 属性将为您完成此操作。这也应该适应任何屏幕方向。
I don't think you need to truncate title manually. Android TextView component has ellipsize attribute that will do that for you. That also should adopt to any screen orientation.