Skip to content

Commit 20d6caf

Browse files
Jean-Baptiste Queruandroid code review
authored andcommitted
Merge "Fix issue #13366. Take account of stackFromBottom in computeVerticalScrollOffset()."
2 parents 0cf3421 + bbf7b4c commit 20d6caf

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

core/java/android/widget/GridView.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2095,8 +2095,13 @@ protected int computeVerticalScrollOffset() {
20952095
int height = view.getHeight();
20962096
if (height > 0) {
20972097
final int numColumns = mNumColumns;
2098-
final int whichRow = mFirstPosition / numColumns;
20992098
final int rowCount = (mItemCount + numColumns - 1) / numColumns;
2099+
// In case of stackFromBottom the calculation of whichRow needs
2100+
// to take into account that counting from the top the first row
2101+
// might not be entirely filled.
2102+
final int oddItemsOnFirstRow = isStackFromBottom() ? ((rowCount * numColumns) -
2103+
mItemCount) : 0;
2104+
final int whichRow = (mFirstPosition + oddItemsOnFirstRow) / numColumns;
21002105
return Math.max(whichRow * 100 - (top * 100) / height +
21012106
(int) ((float) mScrollY / getHeight() * rowCount * 100), 0);
21022107
}

0 commit comments

Comments
 (0)