简体   繁体   English

检查TextView文本是否被截断

[英]Check if a TextView text is cut off the screen


I have a calendar view which is based on a GridView . 我有一个基于GridView的日历视图。
It basically a school tests calendar. 基本上,这是学校的考试日历。 When you click on one of the cells you can see information about the test. 当您单击其中一个单元格时,您可以看到有关测试的信息。 In some phones the TextView containing the information is not shown, or partially shown because the calendar catches the whole screen. 在某些手机中,包含信息的TextView无法显示或部分显示,因为日历会覆盖整个屏幕。 I decided that if the TextView is cut off, I want to show an AlertDialog instead of showing the information on the screen. 我决定如果TextView被切断,我想显示一个AlertDialog而不是在屏幕上显示信息。 The problem is, I don't know how to check if the TextView is cut off. 问题是,我不知道如何检查TextView是否被截断。
Here are 2 pictures to show you what I mean: 这是2张图片,向您展示我的意思:

Thats how it should look: 多数民众赞成应该看起来:

多数民众赞成应该看起来

Thats how it sometimes looks: 那就是有时的样子:

那就是有时候的样子

Thanks! 谢谢!

You can find out what is screen size category (small, medium ...) see here , and then can have different behavior for different screen sizes. 您可以在此处找到什么是屏幕尺寸类别(小,中...),然后针对不同的屏幕尺寸可以具有不同的行为。 In your case you can show AlertDialog in case of small or medium size screens. 在您的情况下,如果屏幕较小或中等,则可以显示AlertDialog。

I have found a solution on my own. 我自己找到了解决方案。 I checked the height of the GridView and the height of the TextView . 我检查了GridView的高度和TextView的高度。 then, 然后,

if (gridViewHeight + textViewHeight >= containingLinearLayoutHeight)

it means that the Text is cut off. 这意味着文本被截断。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM