Android開源:SmartTable-Android 自動生成表格框架

awuzefeng 6年前發布 | 39K 次閱讀 Android 安卓 Android開發 移動開發

SmartTable

一款android自動生成表格框架

功能介紹

  1. 快速配置自動生成表格;
  2. 自動計算表格寬高;
  3. 表格列標題組合;
  4. 表格固定左序列、頂部序列、第一行、列標題、統計行;
  5. 自動統計,排序(自定義統計規則);
  6. 表格圖文、序列號、列標題格式化;
  7. 表格各組成背景、文字、網格、padding等配置;
  8. 表格批注;
  9. 表格內容、列標題點擊事件;
  10. 縮放模式和滾動模式;
  11. 注解模式;
  12. 內容多行顯示;
  13. 分頁模式;
  14. 首尾動態添加數據;
  15. 豐富的格式化;
  16. 支持二維數組展示(用于類似日程表,電影選票等)待完善

視頻展示

如何使用

  • 引用
  • Step 1. 添加 JitPack repository 到你的build文件
allprojects {
        repositories {
            ...
            maven { url 'https://www.jitpack.io' }
        }
    }
  • Step 2. 增加依賴
dependencies {
            compile 'com.github.huangyanbin:SmartTable:1.5'
    }
  • 使用表格View
<com.bin.david.form.core.SmartTable
       android:id="@+id/table"
       android:layout_width="match_parent"
       android:layout_height="match_parent"
      />

- 注解模式

  • 在您需要生成的表格的類增加注解
@SmartTable(name="表名")
  • 在你需要顯示的字段增加注解
// id為該字段所在表格排序位置
 @SmartColumn(id =1,name = "列名")
 //如果需要查詢到該成員變量里面去,通過設置type實現
 @SmartColumn(type = ColumnType.Child)
  • 設置表格數據
table = findViewById(R.id.table);
        table.setData(list);

注解模式就是這么簡單,你可以直接運行查看效果了。當然這只是注解基本配置,注解里面還有自動統計,列組合等,如果你想要了解注解更多,請查看demo.

- 基本模式

//普通列
   Column<String> column1 = new Column<>("姓名", "name");
   Column<Integer> column2 = new Column<>("年齡", "age");
   Column<Long> column3 = new Column<>("更新時間", "time");
    Column<String> column4 = new Column<>("頭像", "portrait");
    //如果是多層,可以通過.來實現多級查詢
      Column<String> column5 = new Column<>("班級", "class.className");
   //組合列
  Column totalColumn1 = new Column("組合列名",column1,column2);

//表格數據 datas是需要填充的數據 final TableData<User> tableData = new TableData<>("表格名",userList,totalColumn1,column3); //設置數據 table = findViewById(R.id.table); //table.setZoom(true,3);是否縮放 table.setTableData(tableData);</code></pre>

- 基本方法介紹

Column 構造方法中還有兩個參數 IFormat<T> , IDrawFormat<T> 。其中 IFormat<T> 是用于格式化顯示文字,比如 User 對象中有更新時間字段 time 時間戳。我們想要顯示不同格式,就可以重寫該方法。 IDrawFormat<T> 是用于顯示繪制格式化,比如 User 對象中有頭像字段 portrait 時間戳,就可以使用該方法,框架提供幾種 IDrawFormat 包括(文字、Bitmap、Resoure圖片、圖文結合)。

Column 提供了

  1. 是否自動排序 setAutoCount(boolean isAutoCount)
  2. 是否反序排列 isReverseSort
  3. 設置排序比較 setComparator
  4. 統計格式化 setCountFormat
  5. 點擊事件 OnColumnItemClickListener

TableData 中基本方法

  1. 設置排序列 setSortColumn
  2. 設置列標題格式化 settitleDrawFormat
  3. 設置頂部序列號格式化 setXSequenceFormat
  4. 設置左邊序列號格式化 setYSequenceFormat
  5. 設置是否顯示統計 setShowCount

TableConfig 中基本方法

  1. 設置內容文字樣式 setContentStyle
  2. 設置左邊序列文字樣式 setYSequenceStyle
  3. 設置頂部序列文字樣式 setXSequenceStyle
  4. 設置列標題文字樣式 setColumnTitleStyle
  5. 設置表格標題文字樣式 setTableTitleStyle
  6. 設置統計行樣式 setCountStyle
  7. 設置列標題網格樣式 setColumnTitleGridStyle
  8. 設置表格網格樣式 setGridStyle
  9. 設置網格列padding setVerticalPadding
  10. 設置網格行padding setHorizontalPadding
  11. 設置左序列背景 setYSequenceBackgroundColor
  12. 設置右序列背景 setXSequenceBackgroundColor
  13. 設置列標題背景 setColumnTitleBackgroundColor
  14. 設置內容背景 setContentBackgroundColor
  15. 設置統計行背景 setCountBackgroundColor
  16. 固定左側 setFixedYSequence
  17. 固定頂部 setFixedXSequence
  18. 固定列標題 setFixedTitle
  19. 固定第一列 setFixedFirstColumn //1.4版本取消了
  20. 固定統計行 setFixedCountRow

總結

寫完SmartChart之后,對android 繪圖有了進一步的理解。開始了做SmartTable,開始只是一個小demo,經過一星期的上班偷著寫,基本完成表格主要功能,本來還有合并等功能,由于后面沒有采用,便只做了開始設計功能,已經滿足日常需求。

android中使用表格的場景很少,主要屏幕一頁放不下,用戶體驗不好。在實現過程中,盡量做到體驗感好些,我感覺通過固定標題和第一行體驗最好,所以默認設置固定。當然你可以自己設置。里面還有不少的坑,希望有需要的朋友可以使用它。

License

SmartTable is released under the Apache 2.0 license.

Copyright 2017 Huangyanbin.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at following link.

 http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitat</code></pre>

 

 

 

 本文由用戶 awuzefeng 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!