Merge "Fix overscroll distance calculation for stack-from-bottom ListViews"

This commit is contained in:
Adam Powell
2010-03-11 15:01:56 -08:00
committed by Android (Google) Code Review
2 changed files with 30 additions and 7 deletions

View File

@@ -381,12 +381,12 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
/**
* Maximum distance to overscroll by
*/
private int mOverscrollMax;
int mOverscrollMax;
/**
* Content height divided by this is the overscroll limit.
*/
private static final int OVERSCROLL_LIMIT_DIVISOR = 3;
static final int OVERSCROLL_LIMIT_DIVISOR = 3;
/**
* Used to request a layout when we changed touch mode
@@ -2390,7 +2390,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
awakenScrollBars();
}
private int getOverscrollMax() {
int getOverscrollMax() {
final int childCount = getChildCount();
if (childCount > 0) {
return Math.min(mOverscrollMax,

View File

@@ -1250,10 +1250,19 @@ public class ListView extends AbsListView {
int findMotionRow(int y) {
int childCount = getChildCount();
if (childCount > 0) {
for (int i = 0; i < childCount; i++) {
View v = getChildAt(i);
if (y <= v.getBottom()) {
return mFirstPosition + i;
if (!mStackFromBottom) {
for (int i = 0; i < childCount; i++) {
View v = getChildAt(i);
if (y <= v.getBottom()) {
return mFirstPosition + i;
}
}
} else {
for (int i = childCount - 1; i >= 0; i--) {
View v = getChildAt(i);
if (y >= v.getTop()) {
return mFirstPosition + i;
}
}
}
}
@@ -3682,6 +3691,20 @@ public class ListView extends AbsListView {
mCheckedIdStates.clear();
}
}
@Override
int getOverscrollMax() {
if (mStackFromBottom) {
final int childCount = getChildCount();
if (childCount > 0) {
return Math.min(mOverscrollMax,
(getHeight() - getChildAt(0).getTop()) / OVERSCROLL_LIMIT_DIVISOR);
} else {
return mOverscrollMax;
}
}
return super.getOverscrollMax();
}
static class SavedState extends BaseSavedState {
SparseBooleanArray checkState;