Skip to content

Commit

Permalink
1. 处理 LabelFlowlayout 使用 Header,如果刚好换行,header 不起作用的问题
Browse files Browse the repository at this point in the history
2. LabelActivity 调用 notifyDataChanged 不能选中第一个的问题
  • Loading branch information
LillteZheng committed Mar 29, 2023
1 parent 19e48f7 commit 812eef0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
* 是否设置了显示行数
Expand All @@ -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;
Expand All @@ -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;
}
}


Expand Down Expand Up @@ -357,6 +369,14 @@ private void measureVertical(int widthMeasureSpec, int heightMeasureSpec) {
setMeasuredDimension(widthSize, height);
}

private int processHeaderView(int height,int lineHeight,List<View> 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) {
Expand Down

0 comments on commit 812eef0

Please sign in to comment.