Skip to content

Commit 0fc76be

Browse files
committed
2021-3-15 19:59:23
1 parent 6c3e08e commit 0fc76be

File tree

9 files changed

+81
-121
lines changed

9 files changed

+81
-121
lines changed

app/src/main/java/com/boylab/example/MainActivity.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import android.os.Bundle;
66
import android.util.Log;
7+
import android.view.View;
78

89
import com.boylab.example.bean.Student;
910
import com.boylab.example.bean.StudentLabel;
@@ -30,5 +31,12 @@ protected void onCreate(Bundle savedInstanceState) {
3031
TableView tableView = findViewById(R.id.tableView);
3132
tableView.setTableData(new StudentLabel(), mTableDatas);
3233

34+
/*tableView.setmOnItemClickListenter(new TableView.OnItemClickListenter() {
35+
@Override
36+
public void onItemClick(View item, int position) {
37+
38+
}
39+
});*/
40+
3341
}
3442
}
Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
package com.boylab.example.bean;
22

3-
import com.boylab.protocol.ItemRect;
43
import com.boylab.protocol.ItemRow;
54

65
import java.util.ArrayList;
76
import java.util.HashMap;
87
import java.util.List;
98

10-
public class StudentLabel implements ItemRow, ItemRect {
9+
public class StudentLabel implements ItemRow {
1110

1211
public static final int SIZE = 24;
1312
private final List<String> label = new ArrayList<String>(){{
@@ -40,29 +39,4 @@ public String get(int position) {
4039
return "N/A";
4140
}
4241

43-
@Override
44-
public int getHeight() {
45-
return 60;
46-
}
47-
48-
private HashMap<Integer, Integer> itemWidth = new HashMap<Integer, Integer>(){{
49-
put(0, 100);
50-
put(1, 100);
51-
put(2, 100);
52-
put(3, 100);
53-
put(4, 100);
54-
put(5, 100);
55-
put(6, 100);
56-
put(7, 100);
57-
put(8, 100);
58-
put(9, 100);
59-
put(10, 100);
60-
put(11, 100);
61-
put(12, 100);
62-
}};
63-
64-
@Override
65-
public int getWidth(int column) {
66-
return itemWidth.get(column);
67-
}
6842
}

app/src/main/java/com/boylab/example/bean/StudentRect.java

Lines changed: 0 additions & 37 deletions
This file was deleted.

app/src/main/res/layout/activity_main.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<com.boylab.scrolltable.TableView
1010
android:id="@+id/tableView"
1111
android:layout_width="match_parent"
12-
android:layout_height="match_parent"/>
12+
android:layout_height="match_parent"
13+
app:rowWidths="@array/WithList"/>
1314

1415
</RelativeLayout>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,29 @@
11
<resources>
22
<string name="app_name">ScrollTable</string>
3+
4+
<integer-array name="WithList">
5+
<item>160</item>
6+
<item>160</item>
7+
<item>160</item>
8+
<item>160</item>
9+
<item>160</item>
10+
<item>160</item>
11+
<item>160</item>
12+
<item>160</item>
13+
<item>160</item>
14+
<item>200</item>
15+
<item>200</item>
16+
<item>200</item>
17+
<item>200</item>
18+
<item>160</item>
19+
<item>160</item>
20+
<item>160</item>
21+
<item>160</item>
22+
<item>160</item>
23+
<item>160</item>
24+
<item>160</item>
25+
<item>160</item>
26+
<item>160</item>
27+
</integer-array>
28+
329
</resources>

mylibrary/src/main/java/com/boylab/protocol/ItemRect.java

Lines changed: 0 additions & 23 deletions
This file was deleted.

mylibrary/src/main/java/com/boylab/scrolltable/SynScrollerLayout.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ class SynScrollerLayout extends HorizontalScrollView {
1919
private int mPosition = -1;
2020
private View mItemView;
2121
private OnItemClickListener mOnItemClickListener;
22-
private int mNomarlColor = getDrawingCacheBackgroundColor();
23-
private int mSelectColor = Color.GRAY;
22+
/*private int mNomarlColor = getDrawingCacheBackgroundColor();
23+
private int mSelectColor = Color.GRAY;*/
2424

2525

2626
private float mStartX;
@@ -38,13 +38,13 @@ public SynScrollerLayout(Context context, AttributeSet attrs, int defStyleAttr)
3838
super(context, attrs, defStyleAttr);
3939
}
4040

41-
public void setNomarlColor(int nomarlColor) {
41+
/*public void setNomarlColor(int nomarlColor) {
4242
mNomarlColor = nomarlColor;
4343
}
4444
4545
public void setSelectColor(int selectColor) {
4646
mSelectColor = selectColor;
47-
}
47+
}*/
4848

4949
@Override
5050
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
@@ -102,7 +102,7 @@ private void actionMove(MotionEvent event) {
102102
float dx = Math.abs(x - mStartX);
103103
if (dx > 50 || dy > 0) {
104104
if (mItemView != null) {
105-
mItemView.setBackgroundColor(mNomarlColor);
105+
//mItemView.setBackgroundColor(mNomarlColor);
106106
removeCallbacks(mMoveAction);
107107
}
108108
}
@@ -116,17 +116,17 @@ private void actionUp(MotionEvent event) {
116116
float dx = Math.abs(x - mStartX);
117117
if (dx < 50 && dy < 50) {
118118
if (mPosition != -1 && mItemView != null) {
119-
mItemView.setBackgroundColor(mSelectColor);
119+
//mItemView.setBackgroundColor(mSelectColor);
120120

121121
postDelayed(mUpAction, 50);
122122
if (mOnItemClickListener != null) {
123123
mOnItemClickListener.onClick(mItemView, mPosition);
124124
}
125125
}
126126
} else {
127-
if (mItemView != null) {
127+
/*if (mItemView != null) {
128128
mItemView.setBackgroundColor(mNomarlColor);
129-
}
129+
}*/
130130
mPosition = -1;
131131
mItemView = null;
132132
}
@@ -136,7 +136,7 @@ private void actionUp(MotionEvent event) {
136136
@Override
137137
public void run() {
138138
if (mItemView != null) {
139-
mItemView.setBackgroundColor(mNomarlColor);
139+
//mItemView.setBackgroundColor(mNomarlColor);
140140
mPosition = -1;
141141
mItemView = null;
142142
removeCallbacks(mUpAction);
@@ -147,7 +147,7 @@ public void run() {
147147
@Override
148148
public void run() {
149149
if (mItemView != null) {
150-
mItemView.setBackgroundColor(mSelectColor);
150+
//mItemView.setBackgroundColor(mSelectColor);
151151
}
152152
}
153153
};

mylibrary/src/main/java/com/boylab/scrolltable/TableView.java

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.content.Context;
44
import android.content.res.TypedArray;
55
import android.util.AttributeSet;
6+
import android.util.Log;
67
import android.view.MotionEvent;
78
import android.view.View;
89
import android.view.ViewGroup;
@@ -24,6 +25,7 @@
2425
import com.scwang.smart.refresh.layout.listener.OnRefreshListener;
2526

2627
import java.util.ArrayList;
28+
import java.util.Arrays;
2729
import java.util.HashMap;
2830
import java.util.Set;
2931

@@ -61,7 +63,7 @@ public class TableView extends LinearLayout {
6163
/**
6264
* 参数
6365
*/
64-
private HashMap<Integer, Integer> itemWidth = new HashMap<>();
66+
private HashMap<Integer, Integer> itemWidths = new HashMap<>();
6567
private float itemHeight = TableParams.HEIGHT;
6668
private int divider = getContext().getResources().getColor(android.R.color.darker_gray);
6769
private TableParams headParams, leftParams, contentParams;
@@ -88,30 +90,39 @@ private void parseRes(Context context, AttributeSet attrs) {
8890
if (attrs != null) {
8991
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.TableView);
9092

91-
int resourceId = typedArray.getResourceId(R.styleable.TableView_tableRowWidth, 0);
93+
int resourceId = typedArray.getResourceId(R.styleable.TableView_rowWidths, 0);
9294
if (resourceId != 0){
9395
int[] intArray = getResources().getIntArray(resourceId);
96+
//Log.i(">>>>>>", "parseRes: "+ Arrays.toString(intArray));
9497
if (intArray != null) {
9598
for (int i = 0; i < intArray.length; i++) {
96-
itemWidth.put(i, intArray[i]);
99+
itemWidths.put(i, intArray[i]);
97100
}
98101
}
102+
/*String string = "";
103+
for (int i = 0; i < intArray.length; i++) {
104+
string = string+ itemWidths.get(i) + " ";
105+
}
106+
Log.i(">>>>>>", "parseRes: "+ string);*/
99107
}
100108

101-
itemHeight = typedArray.getDimension(R.styleable.TableView_tableRowHeight, TableParams.HEIGHT);
109+
itemHeight = typedArray.getDimension(R.styleable.TableView_rowHeight, TableParams.HEIGHT);
102110
headParams.setHeight((int) itemHeight);
103-
headParams.setItemWidth(itemWidth);
111+
headParams.setItemWidth(itemWidths);
104112
leftParams.setHeight((int) itemHeight);
105-
leftParams.setItemWidth(itemWidth);
113+
leftParams.setItemWidth(itemWidths);
106114
contentParams.setHeight((int) itemHeight);
107-
contentParams.setItemWidth(itemWidth);
115+
contentParams.setItemWidth(itemWidths);
108116

109-
divider = typedArray.getColor(R.styleable.TableView_tableDivider, getResources().getColor(android.R.color.darker_gray));
110-
int foucsColor = typedArray.getColor(R.styleable.TableView_tableFoucsColor, getResources().getColor(android.R.color.holo_blue_bright));
117+
divider = typedArray.getColor(R.styleable.TableView_rowDivider, getResources().getColor(android.R.color.darker_gray));
118+
int foucsColor = typedArray.getColor(R.styleable.TableView_rowFoucsColor, getResources().getColor(android.R.color.holo_blue_bright));
111119
headParams.setFoucsColor(foucsColor);
112120
leftParams.setFoucsColor(foucsColor);
113121
contentParams.setFoucsColor(foucsColor);
114122

123+
/**
124+
* 标头部参数
125+
*/
115126
float headTextSize = typedArray.getDimension(R.styleable.TableView_headTextSize, TableParams.TEXT_SIZE);
116127
int headTextColor = typedArray.getColor(R.styleable.TableView_headTextColor, getResources().getColor(android.R.color.black));
117128
int headBackgroundColor = typedArray.getColor(R.styleable.TableView_headBackgroundColor, getResources().getColor(android.R.color.holo_blue_light));
@@ -130,6 +141,9 @@ private void parseRes(Context context, AttributeSet attrs) {
130141
headParams.setPaddingRight((int) headPaddingRight);
131142
headParams.setItemGravity(headGravity);
132143

144+
/**
145+
* 表固定列参数
146+
*/
133147
float leftTextSize = typedArray.getDimension(R.styleable.TableView_leftTextSize, TableParams.TEXT_SIZE);
134148
int leftTextColor = typedArray.getColor(R.styleable.TableView_leftTextColor, getResources().getColor(android.R.color.black));
135149
int leftBackgroundColor = typedArray.getColor(R.styleable.TableView_leftBackgroundColor, getResources().getColor(android.R.color.holo_blue_bright));
@@ -148,6 +162,9 @@ private void parseRes(Context context, AttributeSet attrs) {
148162
leftParams.setPaddingRight((int) leftPaddingRight);
149163
leftParams.setItemGravity(leftGravity);
150164

165+
/**
166+
* 表内容参数
167+
*/
151168
float contentTextSize = typedArray.getDimension(R.styleable.TableView_contentTextSize, TableParams.TEXT_SIZE);
152169
int contentTextColor = typedArray.getColor(R.styleable.TableView_contentTextColor, getResources().getColor(android.R.color.black));
153170
int contentBackgroundColor = typedArray.getColor(R.styleable.TableView_contentBackgroundColor, getResources().getColor(android.R.color.white));
@@ -296,7 +313,6 @@ public void onItemLongClick(View item, int position) {
296313
}
297314
}
298315
});
299-
300316
}
301317

302318
public void notifyDataSetChanged() {
@@ -365,9 +381,6 @@ public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
365381
private int divider = getContext().getResources().getColor(android.R.color.darker_gray);
366382
private TableParams headParams, leftParams, contentParams;*/
367383

368-
369-
370-
371384
public void setDivider(int divider) {
372385
this.divider = divider;
373386
layout_HeadView.setBackgroundColor(divider);
@@ -383,7 +396,7 @@ public void setItemHeight(int itemHeight, HashMap<Integer, Integer> itemWidth) {
383396

384397
Set<Integer> keySet = itemWidth.keySet();
385398
for(int key : keySet){
386-
this.itemWidth.put(key, itemWidth.get(key));
399+
this.itemWidths.put(key, itemWidth.get(key));
387400
}
388401

389402
headParams.setHeight((int) this.itemHeight);
@@ -394,18 +407,16 @@ public void setItemHeight(int itemHeight, HashMap<Integer, Integer> itemWidth) {
394407
leftParams.setItemWidth(itemWidth);
395408
contentParams.setItemWidth(itemWidth);
396409

397-
setTextHeading();
410+
freshHeading();
398411
}
399412

400413
public int itemWidth(int column) {
401-
if (itemWidth.containsKey(column)){
402-
return itemWidth.get(column);
414+
if (itemWidths.containsKey(column)){
415+
return itemWidths.get(column);
403416
}
404417
return TableParams.HEIGHT;
405418
}
406419

407-
408-
409420
/**
410421
* 下拉刷新监听
411422
*/

0 commit comments

Comments
 (0)