Skip to content

Commit d97ebb5

Browse files
committed
2021-5-28 10:42:12
1 parent 5636290 commit d97ebb5

File tree

4 files changed

+18
-25
lines changed

4 files changed

+18
-25
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ allprojects {
1818
步骤2:添加依赖库:
1919
```
2020
dependencies {
21-
implementation 'com.github.boylab:ScrollTable:1.0.0'
21+
implementation 'com.github.boylab:ScrollTable:Tag'
2222
}
2323
```
2424
### 2、使用

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ dependencies {
3131
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
3232

3333
implementation project(path: ':mylibrary')
34-
//implementation 'com.github.boylab:ScrollTable:1.0.3'
34+
//implementation 'com.github.boylab:ScrollTable:Tag'
3535

3636
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ protected void onCreate(Bundle savedInstanceState) {
2525
/**
2626
* 查询所得数据
2727
*/
28-
for (int i = 0; i < 3; i++) {
28+
for (int i = 0; i < 30; i++) {
2929
mTableDatas.add(new Student(i));
3030
}
3131

3232
TableView tableView = findViewById(R.id.tableView);
33+
tableView.setEnableRefresh(true);
3334

3435
/**
3536
* 可设置一些参数...
@@ -49,7 +50,7 @@ public void onItemClick(View item, int position) {
4950
/**
5051
* 下拉刷新(用的少)
5152
*/
52-
/*tableView.setOnRefreshListener(new TableView.OnTableRefreshListener() {
53+
tableView.setOnRefreshListener(new TableView.OnTableRefreshListener() {
5354
@Override
5455
public void onRefresh(TableView mTableView) {
5556
mTableDatas.clear();
@@ -69,7 +70,7 @@ public void onRefresh(TableView mTableView) {
6970
mTableView.setEnableLoadMore(true);
7071
}
7172
}
72-
});*/
73+
});
7374

7475

7576
/**

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

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import com.boylab.protocol.ItemRow;
1717

1818
import java.util.ArrayList;
19+
import java.util.List;
1920

2021
public class TableViewAdapter extends RecyclerView.Adapter<TableViewAdapter.ScrollViewHolder> {
2122

@@ -57,11 +58,12 @@ public void onBindViewHolder(final ScrollViewHolder holder, final int position)
5758

5859
holder.text_TableLeft.setText(itemRow.get(0));
5960
int childCount = holder.layout_TableRow.getChildCount();
61+
boolean isFocus = (position == focusRow);
6062
for (int i = 0; i < childCount; i++) {
6163
FrameLayout itemLayout = (FrameLayout) holder.layout_TableRow.getChildAt(i);
6264
TextView text_item = (TextView) itemLayout.getChildAt(0);
6365
text_item.setText(itemRow.get(i + 1));
64-
text_item.setBackgroundColor(position == focusRow ? contentParams.getFoucsColor() : contentParams.getBackgroundColor());
66+
text_item.setBackgroundColor(isFocus ? contentParams.getFoucsColor() : contentParams.getBackgroundColor());
6567
}
6668

6769
mSynScrollerview.setOnScrollListener(new SynScrollerLayout.OnItemScrollView() {
@@ -129,32 +131,22 @@ public void setSynScrollerview(SynScrollerLayout mSynScrollerview) {
129131
this.mSynScrollerview = mSynScrollerview;
130132
}
131133

132-
public void setFocusRow(LinearLayout focusView, int focusRow) {
134+
public void setFocusRow(LinearLayout focusView, final int focusRow) {
133135
if (this.focusRow == focusRow){
134136
return;
135137
}
136138

137-
if (cacheLayout != null){
138-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
139-
if (cacheLayout.isAttachedToWindow()){
140-
int childCount = cacheLayout.getChildCount();
141-
for (int i = 0; i < childCount; i++) {
142-
FrameLayout itemLayout = (FrameLayout) cacheLayout.getChildAt(i);
143-
TextView childAt = (TextView) itemLayout.getChildAt(0);
144-
childAt.setBackgroundColor(contentParams.getBackgroundColor());
145-
}
146-
}
147-
}
148-
}
139+
int oldFocusRow = this.focusRow;
149140
this.focusRow = focusRow;
150141
this.cacheLayout = focusView;
151142

152-
int childCount = cacheLayout.getChildCount();
153-
for (int i = 0; i < childCount; i++) {
154-
FrameLayout itemLayout = (FrameLayout) cacheLayout.getChildAt(i);
155-
TextView childAt = (TextView) itemLayout.getChildAt(0);
156-
childAt.setBackgroundColor(contentParams.getFoucsColor());
157-
}
143+
if (oldFocusRow != -1){
144+
notifyItemChanged(oldFocusRow, false);
145+
}
146+
147+
if (this.focusRow != -1){
148+
notifyItemChanged(focusRow, true);
149+
}
158150
}
159151

160152
public int getFocusRow() {

0 commit comments

Comments
 (0)