diff options
| author | Adam Powell <adamp@google.com> | 2010-02-12 15:25:33 -0800 |
|---|---|---|
| committer | Adam Powell <adamp@google.com> | 2010-02-12 15:54:59 -0800 |
| commit | f2a204e792df5593cfe54efc95d04b7e764795c1 (patch) | |
| tree | 788910a7e3d018957002806fd603f221dc493432 /core/java/android/widget/GridView.java | |
| parent | 60d21566fcfe1bb9d84e745c1ddc537555094acd (diff) | |
Added proper overscrolling scroll bar behavior to GridView
Diffstat (limited to 'core/java/android/widget/GridView.java')
| -rw-r--r-- | core/java/android/widget/GridView.java | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/core/java/android/widget/GridView.java b/core/java/android/widget/GridView.java index 30a38df954e2..b9acf5ec38b5 100644 --- a/core/java/android/widget/GridView.java +++ b/core/java/android/widget/GridView.java @@ -1856,8 +1856,11 @@ public class GridView extends AbsListView { final int top = view.getTop(); int height = view.getHeight(); if (height > 0) { - final int whichRow = mFirstPosition / mNumColumns; - return Math.max(whichRow * 100 - (top * 100) / height, 0); + final int numColumns = mNumColumns; + final int whichRow = mFirstPosition / numColumns; + final int rowCount = (mItemCount + numColumns - 1) / numColumns; + return Math.max(whichRow * 100 - (top * 100) / height + + (int) ((float) mScrollY / getHeight() * rowCount * 100), 0); } } return 0; @@ -1868,7 +1871,12 @@ public class GridView extends AbsListView { // TODO: Account for vertical spacing too final int numColumns = mNumColumns; final int rowCount = (mItemCount + numColumns - 1) / numColumns; - return Math.max(rowCount * 100, 0); + int result = Math.max(rowCount * 100, 0); + if (mScrollY != 0) { + // Compensate for overscroll + result += Math.abs((int) ((float) mScrollY / getHeight() * rowCount * 100)); + } + return result; } } |
