diff --git a/tablibx/src/main/java/com/zhengsr/tablib/view/flow/LabelFlowLayout.java b/tablibx/src/main/java/com/zhengsr/tablib/view/flow/LabelFlowLayout.java index 652b1d4..94bf6ee 100644 --- a/tablibx/src/main/java/com/zhengsr/tablib/view/flow/LabelFlowLayout.java +++ b/tablibx/src/main/java/com/zhengsr/tablib/view/flow/LabelFlowLayout.java @@ -264,6 +264,7 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { * 更新数据 */ private void notifyData() { + mLastPosition = -1; removeAllViews(); int childCount = mAdapter.getItemCount(); for (int i = 0; i < childCount; i++) { diff --git a/tablibx/src/main/java/com/zhengsr/tablib/view/flow/base/FlowLayout.java b/tablibx/src/main/java/com/zhengsr/tablib/view/flow/base/FlowLayout.java index d39a6f0..27b682b 100644 --- a/tablibx/src/main/java/com/zhengsr/tablib/view/flow/base/FlowLayout.java +++ b/tablibx/src/main/java/com/zhengsr/tablib/view/flow/base/FlowLayout.java @@ -289,6 +289,13 @@ private void measureVertical(int widthMeasureSpec, int heightMeasureSpec) { //重置为下一个child 的宽度 lineWidth = cWidth; lineHeight = cHeight; + if (isHeader){ + height = processHeaderView(height,lineHeight,lineViews); + lineViews = new ArrayList<>(); + //重置为下一个child 的宽度 + lineWidth = 0; + lineHeight = 0; + } /** * 是否设置了显示行数 @@ -305,10 +312,8 @@ private void measureVertical(int widthMeasureSpec, int heightMeasureSpec) { if (isHeader) { //查看上一个 if (i > 0 && getChildAt(i - 1) != null) { - //// 如果当前子视图是头部视图,并且上一个子视图不为空,则另起一行 - height += lineHeight; - mLineHeights.add(lineHeight); - mAllViews.add(lineViews); + // 如果当前子视图是头部视图,并且上一个子视图不为空,则另起一行 + height = processHeaderView(height,lineHeight,lineViews); lineViews = new ArrayList<>(); //重置为下一个child 的宽度 lineWidth = 0; @@ -322,13 +327,20 @@ private void measureVertical(int widthMeasureSpec, int heightMeasureSpec) { if (isHeader) { //换行 - height += lineHeight; - mLineHeights.add(lineHeight); - mAllViews.add(lineViews); + height = processHeaderView(height,lineHeight,lineViews); lineViews = new ArrayList<>(); //重置为下一个child 的宽度 lineWidth = 0; lineHeight = 0; + /** + * 是否设置了显示行数 + */ + if (mLabelLines != -1 && mLineHeights.size() >= mLabelLines) { + isLabelMoreLine = true; + break; + } else { + isLabelMoreLine = false; + } } @@ -357,6 +369,14 @@ private void measureVertical(int widthMeasureSpec, int heightMeasureSpec) { setMeasuredDimension(widthSize, height); } + private int processHeaderView(int height,int lineHeight,List lineViews){ + //换行 + height += lineHeight; + mLineHeights.add(lineHeight); + mAllViews.add(lineViews); + return height; + } + @Override protected void onLayout(boolean changed, int l, int t, int r, int b) {