gpt4 book ai didi

具有固定页眉和页脚的 Android ListView

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:32:29 24 4
gpt4 key购买 nike

如何创建具有固定页眉和页脚的 ListView

我不希望页眉/页脚随 ListView 中的项目一起滚动。

页眉/页脚是否有可能 float 在 ListView 上,这样页眉/页脚就不需要有直的底部/顶部背景和 ListView 项目滚动到页眉/页脚 View 的背景下方,但仍显示列表的第一个元素?

最佳答案

我通过使用@blackbelt 建议和一个带有平铺背景的透明源图像的小型 ImageView 解决了这个问题。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical" >

<ListView
android:id="@+id/lv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_above="@+id/tv_footer"
android:layout_below="@+id/tv_header" />

<TextView
android:id="@+id/tv_footer"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="@drawable/footer_bg"
android:gravity="center"
android:text="Footer" />

<TextView
android:id="@+id/tv_header"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:background="@drawable/header_bg"
android:gravity="center"
android:orientation="vertical"
android:text="Header" />

<ImageView
android:id="@+id/iconView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="@drawable/ic_launcher" />

<ImageView
android:id="@+id/imageView2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignTop="@+id/lv"
android:background="@drawable/header_bg2"
android:src="@drawable/transparant_bg_tile" />

<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/tv_footer"
android:layout_alignParentRight="true"
android:background="@drawable/footer_bg2"
android:src="@drawable/transparant_bg_tile" />

</RelativeLayout>

设备截图 enter image description here

关于具有固定页眉和页脚的 Android ListView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16812191/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com