Skip to content

Commit

Permalink
增加使用
Browse files Browse the repository at this point in the history
  • Loading branch information
huangyanbin committed Mar 15, 2018
1 parent ac1a0df commit e21a1a4
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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)));
}


Expand Down
89 changes: 89 additions & 0 deletions use.md
Original file line number Diff line number Diff line change
@@ -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<CellInfo>() {
@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<CellInfo>() {...});
table.getConfig().setColumnCellBackgroundFormat(new ICellBackgroundFormat<CellInfo>() {...});
table.getConfig().setCountBgCellFormat(new ICellBackgroundFormat<CellInfo>() {...});
table.getConfig().setXSequenceCellBgFormat(new ICellBackgroundFormat<CellInfo>() {...});
table.getConfig().setYSequenceCellBgFormat(new ICellBackgroundFormat<CellInfo>() {...}) ;
```

> 细心的同学肯定发现,组件背景实现是```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<Integer> backgroundFormat = new BaseCellBackgroundFormat<Integer>() {
@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;
}
};
```

0 comments on commit e21a1a4

Please sign in to comment.