Android中ScrollView内TextView多行内容被截断问题求助
嘿,我太懂这种糟心的情况了!当TextView嵌套在ScrollView里,还放在LinearLayout布局中时,末尾内容被截断大多是布局测量逻辑的锅,给你几个经过验证的解决办法:
给ScrollView添加
fillViewport属性
这是最常用的修复手段,ScrollView默认不会填充父布局的可用空间,加上android:fillViewport="true"后,它会强制占满父容器的高度,让TextView能正确计算自身的完整高度。修改后的ScrollView代码:<ScrollView android:layout_width="match_parent" android:layout_height="wrap_content" android:fillViewport="true">检查TextView的关键属性
确保TextView没有被限制显示行数,同时关闭文本省略功能:<TextView android:id="@+id/tv_description" android:layout_width="match_parent" android:layout_height="wrap_content" android:ellipsize="none" <!-- 关闭文本省略,避免末尾被截断 --> android:text="你的多行长文本内容"/>注意不要设置
android:maxLines或者android:lines属性(除非你确实需要限制行数),否则会直接截断超出的内容。调整ScrollView的高度属性
如果上面的方法没生效,可以试试把ScrollView的layout_height从wrap_content改成match_parent。因为LinearLayout是垂直方向布局时,ScrollView用wrap_content可能无法准确计算自身高度,导致TextView的内容无法完全展示:<ScrollView android:layout_width="match_parent" android:layout_height="match_parent">确认LinearLayout的基线对齐设置
你已经给LinearLayout加了android:baselineAligned="false",这个设置很正确!它能避免LinearLayout为了对齐子View的基线而压缩ScrollView的空间,继续保持这个设置就好。
内容的提问来源于stack exchange,提问作者Alastair Gordon

