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

如何始终在底部显示TextView?当前使用ListView展示列表条目

实现ListView底部固定显示TextView的方案

嗨,我来帮你搞定这个需求!要让TextView始终稳稳固定在屏幕底部,同时上方是可滚动的ListView,这里有两种简单靠谱的实现方式,你可以根据自己的布局情况选:

方法一:使用RelativeLayout布局

RelativeLayout可以很方便地控制视图之间的相对位置,直接让TextView贴在父布局底部,ListView放在它的上方就行。

示例代码如下:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- 上方的ListView -->
    <ListView
        android:id="@+id/list_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@id/bottom_text" />

    <!-- 底部固定的TextView -->
    <TextView
        android:id="@+id/bottom_text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:text="这里是底部固定的文本"
        android:padding="16dp"
        android:background="#f0f0f0" />

</RelativeLayout>

关键属性说明:

  • android:layout_alignParentBottom="true":让TextView牢牢贴在布局底部
  • android:layout_above="@id/bottom_text":让ListView的底部始终在TextView上方,不会被遮挡

方法二:使用LinearLayout结合layout_weight属性

如果你的布局是线性结构,用LinearLayout也能轻松实现,给ListView设置权重让它占据剩余空间,TextView自然就留在底部了。

示例代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <!-- 上方的ListView,设置权重占据剩余空间 -->
    <ListView
        android:id="@+id/list_view"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />

    <!-- 底部固定的TextView -->
    <TextView
        android:id="@+id/bottom_text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="这里是底部固定的文本"
        android:padding="16dp"
        android:background="#f0f0f0" />

</LinearLayout>

关键属性说明:

  • android:layout_height="0dp":配合权重使用,让ListView的高度由权重决定
  • android:layout_weight="1":让ListView占据LinearLayout中除TextView之外的所有垂直空间,这样TextView就会固定在底部

两种方法都能实现你要的效果,选哪种就看你现有布局的结构啦!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.27 06:53:56