Skip to content

Commit

Permalink
解决合并单元格导致格子高度过大问题。
Browse files Browse the repository at this point in the history
  • Loading branch information
huangyanbin committed Mar 27, 2018
1 parent 9468be5 commit 623bc05
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,14 @@ protected void onCreate(Bundle savedInstanceState) {

List<MergeInfo> list = new ArrayList<>();
for(int i = 0;i <50; i++) {
list.add(new MergeInfo("huang", 18, System.currentTimeMillis(),true,new ChildData("测试1")));
list.add(new MergeInfo("huang", 18, System.currentTimeMillis(),true,new ChildData("测试1")));
list.add(new MergeInfo("huang", 18, System.currentTimeMillis(),true,new ChildData("测试1")));
list.add(new MergeInfo("huang", 18, System.currentTimeMillis(),true,new ChildData("测试1")));
list.add(new MergeInfo("huang", 18, System.currentTimeMillis(),true,new ChildData("测试1")));
list.add(new MergeInfo("li", 23, System.currentTimeMillis(),false,null));
list.add(new MergeInfo("li", 23, System.currentTimeMillis(),false,null));
list.add(new MergeInfo("li", 23, System.currentTimeMillis(),false,null));
list.add(new MergeInfo("li", 23, System.currentTimeMillis(),false,null));
list.add(new MergeInfo("huangyanbinhuangyanbinhuangyanbinhuangyanbin", 18, System.currentTimeMillis(),true,new ChildData("测试1")));
list.add(new MergeInfo("huangyanbinhuangyanbinhuangyanbinhuangyanbin", 18, System.currentTimeMillis(),true,new ChildData("测试1")));
list.add(new MergeInfo("huangyanbinhuangyanbinhuangyanbinhuangyanbin", 18, System.currentTimeMillis(),true,new ChildData("测试1")));
list.add(new MergeInfo("huangyanbinhuangyanbinhuangyanbinhuangyanbin", 18, System.currentTimeMillis(),true,new ChildData("测试1")));
list.add(new MergeInfo("lihuangyanbinhuangyanbinhuangyanbinhuangyanbin", 23, System.currentTimeMillis(),false,null));
list.add(new MergeInfo("lihuangyanbinhuangyanbinhuangyanbinhuangyanbin", 23, System.currentTimeMillis(),false,null));
list.add(new MergeInfo("lihuangyanbinhuangyanbinhuangyanbinhuangyanbin", 23, System.currentTimeMillis(),false,null));
list.add(new MergeInfo("lihuangyanbinhuangyanbinhuangyanbinhuangyanbin", 23, System.currentTimeMillis(),false,null));
}
table = (SmartTable<MergeInfo>) findViewById(R.id.table);
table.setData(list);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ public void onClick(Column column, UserInfo userInfo, int col, int row) {
}
});


table.getConfig().setSequenceHorizontalPadding(50);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
@SmartTable(name="合并信息列表",count = true)
public class MergeInfo {
@SmartColumn(id =1,name = "姓名",autoCount = true,autoMerge = true)
@SmartColumn(id =1,name = "姓名",autoCount = true,autoMerge = true,width = 100)
private String name;
@SmartColumn(id=2,name="年龄",autoCount = true,autoMerge = true)
private int age;
Expand Down
19 changes: 18 additions & 1 deletion form/src/main/java/com/bin/david/form/core/TableMeasurer.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,24 @@ private int getTableWidth(TableData<T> tableData,TableConfig config){
* @param position
*/
private void measureRowHeight(TableConfig config, int[] lineHeightArray, Column column, int currentPosition,int position) {
int height = column.getDrawFormat().measureHeight(column,position,config) +2*config.getVerticalPadding();

int height =0;
if(column.getRanges() != null && column.getRanges().size() >0){
//如果有合并的情况,将合并的高度分散到各个格子里面去
for(int i = 0; i < column.getRanges().size();i++){
int[] range = (int[]) column.getRanges().get(i);
if(range !=null && range.length ==2){
if(range[0] <= position && range[1] >=position){
height = (column.getDrawFormat().measureHeight(column,range[0],config) +
2*config.getVerticalPadding())/(range[1]- range[0]+1);
}
}
}
}
if(height == 0){
height = column.getDrawFormat().measureHeight(column,position,config) +
2*config.getVerticalPadding();
}
height = Math.max(column.getMinHeight(),height);
if (height > lineHeightArray[currentPosition]) {
lineHeightArray[currentPosition] = height;
Expand Down
8 changes: 8 additions & 0 deletions form/src/main/java/com/bin/david/form/data/column/Column.java
Original file line number Diff line number Diff line change
Expand Up @@ -728,4 +728,12 @@ public int getWidth() {
}
return width;
}

public List<int[]> getRanges() {
return ranges;
}

public void setRanges(List<int[]> ranges) {
this.ranges = ranges;
}
}

0 comments on commit 623bc05

Please sign in to comment.