You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android中ScrollView内TextView多行内容被截断问题求助

解决TextView嵌套ScrollView内容末尾截断的问题

嘿,我太懂这种糟心的情况了!当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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 09:44:56