一个简单的自定义表格 View,可锁定首行和首列
- 添加依赖
implementation'com.github.abigbread:SimpleTableView:1.0.0'- 项目根目录下的 build.gradle 中加入:
allprojects {
repositories {
...
maven { url'https://jitpack.io' }
}
}- 方式一:
newSimpleTableView.Builder(this, container, mTableData)
.useDefaultOptions()//默认表格样式
.create();- 方式二:
newSimpleTableView.Builder(this, container, mTableData)
.setLockFirstColumn(true) //是否锁定第一列
.setLockFirstRow(true) //是否锁定第一行
.setMaxColumnWidth(100) //列最大宽度
.setMinColumnWidth(60) //列最小宽度
.setMinRowHeight(20)//行最小高度
.setMaxRowHeight(60)//行最大高度
.setTextSize(16) //单元格字体大小
.setCellPadding(15)//设置单元格内边距(dp)
.setEmptyString("N/A")
.setItemSelectedStatus(true)//设置item选中效果是否开启
.setItemSelectedColor(R.color.selected_bg)//设置item选中颜色
.setContentTextColor(R.color.white)
.setFirstRowBgColor(R.color.head_bg)//表头背景色
.setHeadTextColor(R.color.head_text_color)//表头字体颜色
.setContentTextColor(R.color.content_text_color)//单元格字体颜色;//空值替换值
.create();- 数据格式:
ArrayList<ArrayList<String>> mTableData = newArrayList<>();
ArrayList<String> mFirstData = newArrayList<>();
//第一行mFirstData.add("标题");
for (inti = 0; i < 10; i++) {
mFirstData.add("标题" + i);
}
mTableData.add(mFirstData);
//其他行for (inti = 0; i < 20; i++) {
ArrayList<String> mRowData = newArrayList<>();
mRowData.add("标题" + i);
for (intj = 0; j < 10; j++) {
mRowData.add("数据" + j);
}
mTableData.add(mRowData);
}https://github.com/RmondJone/LockTableView
Copyright (c) 2022abigbreadPermissionisherebygranted, freeofcharge, toanypersonobtainingacopyofthissoftwareandassociateddocumentationfiles (the"Software"), todealintheSoftwarewithoutrestriction, includingwithoutlimitationtherightstouse, copy, modify, merge, publish, distribute, sublicense, and/orsellcopiesoftheSoftware, andtopermitpersonstowhomtheSoftwareisfurnishedtodoso, subjecttothefollowingconditions:
TheabovecopyrightnoticeandthispermissionnoticeshallbeincludedinallcopiesorsubstantialportionsoftheSoftware.
THESOFTWAREISPROVIDED"AS IS", WITHOUTWARRANTYOFANYKIND, EXPRESSORIMPLIED, INCLUDINGBUTNOTLIMITEDTOTHEWARRANTIESOFMERCHANTABILITY,
FITNESSFORAPARTICULARPURPOSEANDNONINFRINGEMENT. INNOEVENTSHALLTHEAUTHORSORCOPYRIGHTHOLDERSBELIABLEFORANYCLAIM, DAMAGESOROTHERLIABILITY, WHETHERINANACTIONOFCONTRACT, TORTOROTHERWISE, ARISINGFROM,
OUTOFORINCONNECTIONWITHTHESOFTWAREORTHEUSEOROTHERDEALINGSINTHESOFTWARE.