listview固定头标

本文介绍了如何在ListView中实现固定头部,通过添加一个headView并根据滑动距离动态显示或隐藏按钮。关键点包括自定义getScrollY方法来获取滑动距离,以及分别设置不同布局的点击事件。示例代码和实现步骤详细说明,有助于开发者实现类似功能。
摘要由CSDN通过智能技术生成

listview固定头标

由于近期需要这个listview固定头部

原来很简单就是ListView增加一个headView头部然后根据滑动的距离判断是否显示隐藏了的按钮

效果图

接下来就是显示代码了首先是布局

主布局

 <?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">
    <LinearLayout
        android:id="@+id/contentss"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <ListView
            android:id="@+id/main_list_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/material_deep_teal_200" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/main_section_b_outside"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:visibility="gone">
        <include
            layout="@layout/main_section_b"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </LinearLayout>
</FrameLayout>

第二个布局也就是headView

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
        <TextView
            android:background="@color/m
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值