Skip to content

Commit 0dccefa

Browse files
committed
支持更多API调用
1 parent 41002a5 commit 0dccefa

File tree

1 file changed

+48
-5
lines changed

1 file changed

+48
-5
lines changed

app/src/main/java/com/example/lvruheng/autoflowlayout/AutoFlowLayout.java

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@ public class AutoFlowLayout extends LinearLayout {
3232
/**
3333
* 记录当前行数
3434
*/
35-
private int count;
35+
private int mCount;
36+
37+
/**
38+
* 是否还有数据没显示
39+
*/
40+
private boolean mHasMoreData;
3641
public AutoFlowLayout(Context context) {
3742
super(context);
3843
}
@@ -98,11 +103,13 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
98103
height += lineHeight;
99104
// 开启记录下一行的高度
100105
lineHeight = childHeight;
101-
count++;
102-
if (count>=mMaxLineNumbers) {
106+
mCount++;
107+
if (mCount>=mMaxLineNumbers) {
108+
setHasMoreData(i+1,cCount);
103109
break;
104110
}
105111
if (mIsSingleLine) {
112+
setHasMoreData(i+1,cCount);
106113
break;
107114
}
108115
} else
@@ -152,11 +159,13 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) {
152159
mAllViews.add(lineViews);
153160
lineWidth = 0;// 重置行宽
154161
lineViews = new ArrayList<View>();
155-
count++;
156-
if (count>=mMaxLineNumbers) {
162+
mCount++;
163+
if (mCount>=mMaxLineNumbers) {
164+
setHasMoreData(i+1,cCount);
157165
break;
158166
}
159167
if (mIsSingleLine) {
168+
setHasMoreData(i+1,cCount);
160169
break;
161170
}
162171
}
@@ -209,6 +218,17 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) {
209218
}
210219
}
211220

221+
/**
222+
* 判断是否还有跟多View未展示
223+
* @param i 当前展示的View
224+
* @param count 总共需要展示的View
225+
*/
226+
private void setHasMoreData(int i, int count) {
227+
if (i<count){
228+
mHasMoreData = true;
229+
}
230+
}
231+
212232
public void setAllViews(List<View> views) {
213233
removeAllViews();
214234
if (views == null || views.size() == 0) {
@@ -235,5 +255,28 @@ public void setSingleLine(boolean isSingle) {
235255
mIsSingleLine = isSingle;
236256
}
237257

258+
/**
259+
* 是否单行显示
260+
* @return true 单行显示 false 多行显示
261+
*/
262+
public boolean isSingleLine() {
263+
return mIsSingleLine;
264+
}
265+
266+
/**
267+
* 支持显示的最大行数
268+
* @return 最大行数
269+
*/
270+
public int getMaxLineNumbers() {
271+
return mMaxLineNumbers;
272+
}
273+
274+
/**
275+
* 是否还有更多数据未显示
276+
* @return true 还有未显示数据 false 完全显示
277+
*/
278+
public boolean hasMoreData() {
279+
return mHasMoreData;
280+
}
238281

239282
}

0 commit comments

Comments
 (0)