Skip to content

Commit e28c06a

Browse files
authored
Fix the issue that dividers become invisible when there is a gone view in the middle (#361)
1 parent 3fd1434 commit e28c06a

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

flexbox/src/main/java/com/google/android/flexbox/FlexboxLayout.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -927,21 +927,21 @@ protected void onDraw(Canvas canvas) {
927927
* {@code false} otherwise
928928
*/
929929
private void drawDividersHorizontal(Canvas canvas, boolean isRtl, boolean fromBottomToTop) {
930-
int currentViewIndex = 0;
931930
int paddingLeft = getPaddingLeft();
932931
int paddingRight = getPaddingRight();
933932
int horizontalDividerLength = Math.max(0, getWidth() - paddingRight - paddingLeft);
934933
for (int i = 0, size = mFlexLines.size(); i < size; i++) {
935934
FlexLine flexLine = mFlexLines.get(i);
936935
for (int j = 0; j < flexLine.mItemCount; j++) {
937-
View view = getReorderedChildAt(currentViewIndex);
936+
int viewIndex = flexLine.mFirstIndex + j;
937+
View view = getReorderedChildAt(viewIndex);
938938
if (view == null || view.getVisibility() == View.GONE) {
939939
continue;
940940
}
941941
LayoutParams lp = (LayoutParams) view.getLayoutParams();
942942

943943
// Judge if the beginning or middle divider is needed
944-
if (hasDividerBeforeChildAtAlongMainAxis(currentViewIndex, j)) {
944+
if (hasDividerBeforeChildAtAlongMainAxis(viewIndex, j)) {
945945
int dividerLeft;
946946
if (isRtl) {
947947
dividerLeft = view.getRight() + lp.rightMargin;
@@ -966,7 +966,6 @@ private void drawDividersHorizontal(Canvas canvas, boolean isRtl, boolean fromBo
966966
flexLine.mCrossSize);
967967
}
968968
}
969-
currentViewIndex++;
970969
}
971970

972971
// Judge if the beginning or middle dividers are needed before the flex line
@@ -1008,7 +1007,6 @@ private void drawDividersHorizontal(Canvas canvas, boolean isRtl, boolean fromBo
10081007
* {@code false} otherwise
10091008
*/
10101009
private void drawDividersVertical(Canvas canvas, boolean isRtl, boolean fromBottomToTop) {
1011-
int currentViewIndex = 0;
10121010
int paddingTop = getPaddingTop();
10131011
int paddingBottom = getPaddingBottom();
10141012
int verticalDividerLength = Math.max(0, getHeight() - paddingBottom - paddingTop);
@@ -1017,14 +1015,15 @@ private void drawDividersVertical(Canvas canvas, boolean isRtl, boolean fromBott
10171015

10181016
// Draw horizontal dividers if needed
10191017
for (int j = 0; j < flexLine.mItemCount; j++) {
1020-
View view = getReorderedChildAt(currentViewIndex);
1018+
int viewIndex = flexLine.mFirstIndex + j;
1019+
View view = getReorderedChildAt(viewIndex);
10211020
if (view == null || view.getVisibility() == View.GONE) {
10221021
continue;
10231022
}
10241023
LayoutParams lp = (LayoutParams) view.getLayoutParams();
10251024

10261025
// Judge if the beginning or middle divider is needed
1027-
if (hasDividerBeforeChildAtAlongMainAxis(currentViewIndex, j)) {
1026+
if (hasDividerBeforeChildAtAlongMainAxis(viewIndex, j)) {
10281027
int dividerTop;
10291028
if (fromBottomToTop) {
10301029
dividerTop = view.getBottom() + lp.bottomMargin;
@@ -1049,7 +1048,6 @@ private void drawDividersVertical(Canvas canvas, boolean isRtl, boolean fromBott
10491048
flexLine.mCrossSize);
10501049
}
10511050
}
1052-
currentViewIndex++;
10531051
}
10541052

10551053
// Judge if the beginning or middle dividers are needed before the flex line

0 commit comments

Comments
 (0)