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

Android Studio中如何显示ListView每个条目的完整内容?

解决ListView条目内容无法完整显示的问题

嘿,我一下子就揪出问题的关键啦!你在TextView的布局里设置了android:singleLine="true",这个属性会强制文本只显示一行,不管内容有多长——这就是你之前调整各种minHeight、wrap_content都没见效的原因,根源是文本本身被限制住了,根本不会换行展开。

具体修复步骤:

  • 直接移除android:singleLine="true"属性(或者改成android:singleLine="false",不过现在更推荐直接去掉,用更灵活的换行逻辑)
  • 保留android:layout_height="wrap_content",让TextView根据内容自动调整高度
  • 可选补充:如果不需要文本末尾的省略号,可以加上android:ellipsize="none"(默认多行时不会显示省略号,但加上更稳妥)

修改后的TextView布局代码:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/listview_item_text"
    android:textColor="@color/colorPrimary"
    android:text="1) When anyone brings a grain offering to the Lord, their offering is to be of the finest flour. They are to pour olive oil on it, put incense on it"
    android:textSize="20sp" <!-- 文字大小建议用sp,适配系统字体缩放 -->
    android:paddingLeft="20dp" <!-- padding用dp更适配不同屏幕 -->
    android:paddingRight="20dp"
    android:paddingTop="10dp"
    android:paddingBottom="10dp"
    android:textStyle="bold"
    android:lineSpacingMultiplier="1.5"
    android:layout_width="match_parent" <!-- fill_parent已被match_parent替代,更规范 -->
    android:layout_height="wrap_content"/>

补充说明:

你之前尝试的调整ListView或TextView的minHeight、wrap_content之所以没用,是因为这些都是调整容器的高度限制,但文本本身被singleLine锁死在单行,容器再怎么允许高度变化,文本也不会换行展开。只要去掉这个属性,TextView就能自动换行,高度跟着内容撑开,ListView的条目自然就能显示完整内容啦。

如果修复后还有小问题,可以检查Adapter里有没有额外的高度限制(比如你之前加的convertView.setMinimumHeight(100);,这个只会强制条目最小高度,不会影响内容展开,所以不是核心问题)。

内容的提问来源于stack exchange,提问作者gsk

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.08 17:38:14