Android StickyListHeadersListView头部悬停 分组列表实现
最近在做分组列表,头部悬停的效果,在github上就搜到了StickyListHeaders(https://github.com/emilsjolander/StickyListHeaders)这个库,自己动手实现了一个demo,实际效果图见文末。
引用类库:
implementation 'se.emilsjolander:stickylistheaders:2.7.0'
子布局item_pay_bill_month_body_list.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"> <TextView
android:id="@+id/item_body_tv1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="内容"
android:textSize="20sp" /> <TextView
android:id="@+id/item_body_tv2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="内容"
android:textSize="20sp" /> <TextView
android:id="@+id/item_body_tv3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="内容"
android:textSize="20sp" /> <TextView
android:id="@+id/item_body_tv4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="内容"
android:textSize="20sp" /> <TextView
android:id="@+id/item_body_tv5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="内容"
android:textSize="20sp" /> </LinearLayout>
头部布局item_pay_bill_month_header_list.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"> <TextView
android:id="@+id/item_head_tv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#f00"
android:text="头部"
android:textSize="30sp" />
</LinearLayout>
列表适配器PayBillMonthListAdapter.java:
package com.aldx.hccraftsman.adapter; import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView; import com.aldx.hccraftsman.R;
import com.aldx.hccraftsman.model.PayBillMonth; import java.util.ArrayList;
import java.util.List; import se.emilsjolander.stickylistheaders.StickyListHeadersAdapter; /**
* author: chenzheng
* created on: 2018/11/3 11:24
* description:
*/
public class PayBillMonthListAdapter extends BaseAdapter implements StickyListHeadersAdapter { private Context context;
private List<PayBillMonth> monthList = new ArrayList<>(); public PayBillMonthListAdapter(Context context) {
this.context = context;
} public void setItems(List<PayBillMonth> monthList) {
this.monthList = monthList;
notifyDataSetChanged();
} //设置数据的个数
@Override
public int getCount() {
return monthList.size();
} //设置item的条数
@Override
public Object getItem(int i) {
return monthList.get(i);
} //获得相应数据集合中特定位置的数据项
@Override
public long getItemId(int i) {
return i;
} //获得头部相应数据集合中特定位置的数据项
@Override
public long getHeaderId(int position) {
return monthList.get(position).yearmonth;
} //绑定内容的数据
@Override
public View getView(int i, View view, ViewGroup viewGroup) { BodyHolder bodyHolder = null;
if (view == null) {
view = LayoutInflater.from(context).inflate(R.layout.item_pay_bill_month_body_list, viewGroup, false);
bodyHolder = new BodyHolder(view);
view.setTag(bodyHolder);
} else {
bodyHolder = (BodyHolder) view.getTag();
}
//设置数据
bodyHolder.bodyTv.setText(monthList.get(i).name); return view;
} //绑定头部的数据
@Override
public View getHeaderView(int position, View convertView, ViewGroup parent) { HeadHolder headHolder = null;
if (convertView == null) {
convertView = LayoutInflater.from(context).inflate(R.layout.item_pay_bill_month_header_list, parent, false);
headHolder = new HeadHolder(convertView);
convertView.setTag(headHolder);
} else {
headHolder = (HeadHolder) convertView.getTag();
}
//设置数据
headHolder.headTv.setText(monthList.get(position).monthName); return convertView;
} //头部的内部类
class HeadHolder {
private TextView headTv; public HeadHolder(View itemHeadView) { headTv = (TextView) itemHeadView.findViewById(R.id.item_head_tv);
}
} //内容的内部类
class BodyHolder {
private TextView bodyTv; public BodyHolder(View itemBodyView) { bodyTv = (TextView) itemBodyView.findViewById(R.id.item_body_tv1);
}
} }
PayBillMonthListActivity.java:
package com.aldx.hccraftsman.activity; import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView; import com.aldx.hccraftsman.R;
import com.aldx.hccraftsman.adapter.PayBillMonthListAdapter;
import com.aldx.hccraftsman.model.PayBillMonth; import java.util.ArrayList;
import java.util.List; import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import se.emilsjolander.stickylistheaders.StickyListHeadersListView; /**
* author: chenzheng
* created on: 2018/11/3 14:36
* description: 月度账单
*/
public class PayBillMonthListActivity extends BaseActivity { @BindView(R.id.back_iv)
ImageView backIv;
@BindView(R.id.layout_back)
LinearLayout layoutBack;
@BindView(R.id.title_tv)
TextView titleTv;
@BindView(R.id.right_tv)
TextView rightTv;
@BindView(R.id.layout_right)
LinearLayout layoutRight;
@BindView(R.id.stickyListView)
StickyListHeadersListView stickyListView; private String companyId;
private List<PayBillMonth> list = new ArrayList<>();
private PayBillMonthListAdapter payBillMonthListAdapter; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pay_bill_month_list);
companyId = getIntent().getStringExtra("companyId");
ButterKnife.bind(this); initView();
initData();
} private void initData() {
for (int i = 0; i < 10; i++) {
PayBillMonth p1 = new PayBillMonth();
p1.yearmonth = 201811;
p1.monthName = "2018年11月";
p1.name = "詹大三" + i;
list.add(p1);
}
for (int i = 0; i < 7; i++) {
PayBillMonth p1 = new PayBillMonth();
p1.yearmonth = 201810;
p1.monthName = "2018年10月";
p1.name = "刘丽丽" + i;
list.add(p1);
}
for (int i = 0; i < 2; i++) {
PayBillMonth p1 = new PayBillMonth();
p1.yearmonth = 201809;
p1.monthName = "2018年09月";
p1.name = "姜大成" + i;
list.add(p1);
}
payBillMonthListAdapter.setItems(list);
} private void initView() {
titleTv.setText("月度账单"); payBillMonthListAdapter = new PayBillMonthListAdapter(this);
stickyListView.setAdapter(payBillMonthListAdapter); } @OnClick({R.id.layout_back, R.id.layout_right})
public void onViewClicked(View view) {
switch (view.getId()) {
case R.id.layout_back:
finish();
break;
case R.id.layout_right:
break;
}
} public static void startActivity(Context context, String companyId) {
Intent intent = new Intent(context, PayBillMonthListActivity.class);
intent.putExtra("companyId", companyId);
context.startActivity(intent);
}
}
页面布局activity_pay_bill_month_list.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"> <include
android:id="@+id/include_id"
layout="@layout/titlelayout_theme"
android:layout_width="match_parent"
android:layout_height="wrap_content" /> <se.emilsjolander.stickylistheaders.StickyListHeadersListView
android:id="@+id/stickyListView"
android:layout_width="match_parent"
android:layout_height="match_parent" /> </LinearLayout>
实体类PayBillMonth:
package com.aldx.hccraftsman.model; /**
* author: chenzheng
* created on: 2018/11/3 14:18
* description:
*/
public class PayBillMonth { public long yearmonth;
public String monthName;
public String name;
public String money;
public String time;
}
效果图:
Android StickyListHeadersListView头部悬停 分组列表实现的更多相关文章
- Android ExpandableListView BaseExpandableListAdapter (类似QQ分组列表)
分组列表视图(ExpandableListView) 和ListView不同的是它是一个两级的滚动列表视图,每一个组可以展开,显示一些子项,类似于QQ列表,这些项目来至于ExpandableListA ...
- 史上最易懂——ReactNative分组列表SectionList使用详情及示例详解
React Native系列 <逻辑性最强的React Native环境搭建与调试> <ReactNative开发工具有这一篇足矣> <解决React Native un ...
- Android学习系列(11)--App列表之拖拽ListView(下)
接着上篇Android学习系列(10)--App列表之拖拽ListView(上)我们继续实现ListView的拖拽效果. 7.重写onTouchEvent()方法. 在这个方法中我们主要是处理 ...
- Android学习系列(10)--App列表之拖拽ListView(上)
研究了很久的拖拽ListView的实现,受益良多,特此与尔共飨. 鉴于这部分内容网上的资料少而简陋,而具体的实现过程或许对大家才有帮助,为了详尽而不失真,我们一步一步分析,分成两篇文章. ...
- [WP8.1UI控件编程]SemanticZoom控件实现分组列表
11.1.5 SemanticZoom实现分组列表 SemanticZoom控件可以让用户实现一种更加高级的列表,这种列表可以对列表的项目进行分组,同时这个SemanticZoom控件会提供两个具有相 ...
- Android Studio鼠标悬停显示注释
Android Studio鼠标悬停显示注释 在AS中配置 如果你想从网上查看注释,到这一步就操作完成. 下面说明让软件使用本地注释: 使用本地注释 以Windows为例: 找到下面文件 C:\Use ...
- Android实现SQLite数据库联系人列表
Android实现SQLite数据库联系人列表 开发工具:Andorid Studio 1.3 运行环境:Android 4.4 KitKat 工程内容 实现一个通讯录查看程序: 要求使用SQLite ...
- Android水平(横向)翻页列表,类似水平GridVIew
Android水平(横向)翻页列表,类似于水平方向的GridView,行列自定义,但要翻页切换,考虑加载性能,当Item数据很多时加载和翻页要流畅,翻页时要有动画效果,效果图如下: 实现方式: 1:翻 ...
- Android学习系列(15)--App列表之游标ListView(索引ListView)
游标ListView,提供索引标签,使用户能够快速定位列表项. 也可以叫索引ListView,有的人称也为Tweaked ListView,可能更形象些吧. 一看图啥都懂了: 1. ...
随机推荐
- Delphi赋
DELPHI者,经典开发工具.美奂美仑之开发环境也. 盖论DELPHI其身世,实为神界之神物,后借宝蓝公司之手,于1990年代,现于江湖. DELPHI一出江湖,码农爱之,企业爱之.一时间,风雨雷动, ...
- P3388 【模板】割点(割顶)&& 桥
题目背景 割点 题目描述 给出一个n个点,m条边的无向图,求图的割点. 输入输出格式 输入格式: 第一行输入n,m 下面m行每行输入x,y表示x到y有一条边 输出格式: 第一行输出割点个数 第二行按照 ...
- gdb tui设置默认窗口高度
gdb -p 12999 -tui 先显示win信息(输入:info win) 显示如下: SRC (35 lines) <has focus> CMD (17 lines) 我们要改的是 ...
- Codeforces 1172D. Nauuo and Portals 构造
原文链接www.cnblogs.com/zhouzhendong/p/CF1172D.html 前言 明哥神仙打cf方式真潇洒.45分钟切D后就不打了? 我当场爆肝D想错方向不会做自闭了. 题解 考虑 ...
- 域渗透复盘(安洵CTF线下)
复盘线下域渗透环境Write Up 0x01 外网web到DMZ进域 外网web入口 joomla应用 192.168.0.5 反序列化打下来 GET /index.php HTTP/1.1 Ho ...
- ZR#1012
## ZR#1012 blog咕咕咕了好久,开始补. 解法: 一个很显然的性质, $ x $ 只能转移到 $ x+1 $ 或者 $ 2x $ 处,所以我们可以以此性质建图,即 $ x $ 向 $ x ...
- FIS3
#npm install -g cnpm --registry=https://registry.npm.taobao.org#cnpm install -g fis3 npm install fis ...
- ubuntu之路——day10.2单一数字评估指标与满足和优化的评估指标
单一数字评估指标: 我们在平时常用到的模型评估指标是精度(accuracy)和错误率(error rate),错误率是:分类错误的样本数站样本总数的比例,即E=n/m(如果在m个样本中有n个样本分类错 ...
- Mac和window生成ssh和查看ssh key
一.MAC系统 mac 系统开始就已经为我们安装了ssh 如果没有安装,首先安装 打开终端:$ ssh -v 查看ssh版本 OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec ...
- 转载【2017-05-20】OpenWrt 打印机共享专用固件 (trunk, r47249)
[2017-05-20 更新]经过研究发现,Windows 共享打印机使用 RAW 数据(不是 RAW 协议)传输,因此 CUPS 可以去掉所有的过滤器和 PPD 文件.因此重新编译了 8M 的 ar ...