From e21a1a4ab2df49ded18d651e17e33dc1baf5574b Mon Sep 17 00:00:00 2001 From: huangyanbin <873825232@qq.com> Date: Thu, 15 Mar 2018 11:44:12 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + .../bin/david/smarttable/MinModeActivity.java | 7 +- use.md | 89 +++++++++++++++++++ 3 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 use.md diff --git a/README.md b/README.md index 49289a0..70e6635 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ * [历史版本介绍](/README_old_version.md/) * [更多功能详情介绍](https://juejin.im/post/5a55ae6c5188257350511a8c) * [apk version 2.0版本下载地址](/img/smartTable.apk) +* [SmartTable2.0基本使用手册持续更新中](/use.md) > ![下载地址](/img/table.png) diff --git a/app/src/main/java/com/bin/david/smarttable/MinModeActivity.java b/app/src/main/java/com/bin/david/smarttable/MinModeActivity.java index a4cd73c..ef7799d 100644 --- a/app/src/main/java/com/bin/david/smarttable/MinModeActivity.java +++ b/app/src/main/java/com/bin/david/smarttable/MinModeActivity.java @@ -2,6 +2,9 @@ import android.content.Context; import android.graphics.Bitmap; +import android.graphics.Canvas; +import android.graphics.Paint; +import android.graphics.Rect; import android.os.Bundle; import android.support.v4.content.ContextCompat; import android.support.v7.app.AppCompatActivity; @@ -15,6 +18,7 @@ import com.bin.david.form.data.column.ColumnInfo; import com.bin.david.form.data.format.bg.BaseBackgroundFormat; import com.bin.david.form.data.format.bg.BaseCellBackgroundFormat; +import com.bin.david.form.data.format.bg.IBackgroundFormat; import com.bin.david.form.data.format.bg.ICellBackgroundFormat; import com.bin.david.form.data.format.draw.BitmapDrawFormat; import com.bin.david.form.data.format.draw.TextImageDrawFormat; @@ -184,8 +188,7 @@ public int getTextColor(Integer position) { table.getConfig().setContentCellBackgroundFormat(backgroundFormat) .setYSequenceCellBgFormat(backgroundFormat2); table.setTableData(tableData); - - + table.getConfig().setContentBackground(new BaseBackgroundFormat(getResources().getColor(R.color.white))); } diff --git a/use.md b/use.md new file mode 100644 index 0000000..4d87022 --- /dev/null +++ b/use.md @@ -0,0 +1,89 @@ +## SmartTable 2.0 + +##### 背景 + +> 在SmartTable 背景分为两类,一种是修改组件整体背景和组件格子背景。举个栗子,你想要修改整个内容区域背景颜色,只需要 + +``` + table.getConfig().setContentBackground(new IBackgroundFormat() { + @Override + public void drawBackground(Canvas canvas, Rect rect, Paint paint) { + paint.setColor(设置你想要的颜色); + canvas.drawRect(rect,paint); + } + }); + +``` +> 而如果你想要内容行间隔交替变色 + +``` +table.getConfig().setContentCellBackgroundFormat(new ICellBackgroundFormat() { + @Override + public void drawBackground(Canvas canvas, Rect rect, CellInfo cellInfo, Paint paint) { + if(cellInfo.row%2==0){ + paint.setColor(设置你想要的颜色); + canvas.drawRect(rect,paint); + } + } + + @Override + public int getTextColor(CellInfo cellInfo) { + return 0; + } + }); + +``` + +> 下面是所有组件背景的配置: + +``` + //设置内容背景 + table.getConfig().setContentBackground(new IBackgroundFormat(){...}); + //设置X序号行背景(顶部序号) + table.getConfig().setXSequenceBackground(new IBackgroundFormat(){...}); + //设置Y序号行背景(左侧序号) + table.getConfig().setYSequenceBackground(new IBackgroundFormat(){...}); + //设置统计行背景 (需要开启统计行) + table.getConfig().setCountBackground(new IBackgroundFormat(){...}); + //设置列标题背景 + table.getConfig().setColumnTitleBackground(new IBackgroundFormat(){...}); +``` + +> 组件格子背景的配置: + +``` + table.getConfig().setContentCellBackgroundFormat(new ICellBackgroundFormat() {...}); + table.getConfig().setColumnCellBackgroundFormat(new ICellBackgroundFormat() {...}); + table.getConfig().setCountBgCellFormat(new ICellBackgroundFormat() {...}); + table.getConfig().setXSequenceCellBgFormat(new ICellBackgroundFormat() {...}); + table.getConfig().setYSequenceCellBgFormat(new ICellBackgroundFormat() {...}) ; +``` + +> 细心的同学肯定发现,组件背景实现是```IBackgroundFormat```,而组件格子背景是实现```ICellBackgroundFormat```。 + +> ```IBackgroundFormat```中需要实现 ```public void drawBackground(Canvas canvas, Rect rect, Paint paint)```,有了画布,绘制范围,画笔三个参数就可以绘制背景了,你可以绘制背景是一个圆,五角星,或者一张图片。如果你只是想设置背景颜色,你可以使用基本实现类```new BaseBackgroundFormat(getResources().getColor(R.color.white))```。 + +> ```ICellBackgroundFormat```中需要实现 ``` public void drawBackground(Canvas canvas, Rect rect, CellInfo cellInfo, Paint paint), public int getTextColor(CellInfo cellInfo)```,有了画布,绘制范围,画笔三个参数就可以绘制背景了,在CellInfo 里面有一个格子的基本信息,比如数据data,行row 列 col ,你可以根据条件判断是否绘制,咋绘制。```getTextColor```方法,你可以根据格子信息来调整字体的颜色,这样可以保持格子的美观。如果你只是想改变格子的北京颜色,你可以使用实现类 ICellBackgroundFormat + + 下面是内容背景间隔颜色实例 +``` + ICellBackgroundFormat backgroundFormat = new BaseCellBackgroundFormat() { + @Override + public int getBackGroundColor(Integer position) { + if(position%2 == 0){ + return ContextCompat.getColor(MinModeActivity.this,R.color.arc1); + } + return TableConfig.INVALID_COLOR; + + } + + + @Override + public int getTextColor(Integer position) { + if(position%2 == 0) { + return ContextCompat.getColor(MinModeActivity.this, R.color.white); + } + return TableConfig.INVALID_COLOR; + } + }; +```