33import android .content .Context ;
44import android .content .res .TypedArray ;
55import android .util .AttributeSet ;
6+ import android .util .Log ;
67import android .view .MotionEvent ;
78import android .view .View ;
89import android .view .ViewGroup ;
2425import com .scwang .smart .refresh .layout .listener .OnRefreshListener ;
2526
2627import java .util .ArrayList ;
28+ import java .util .Arrays ;
2729import java .util .HashMap ;
2830import 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