Index: chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/NewTabPageRecyclerView.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/NewTabPageRecyclerView.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/NewTabPageRecyclerView.java |
index b0c46c378111f840052f583fa1543a9d1a58623e..34442a74d5f0f63709563899de6c6c9ee1643694 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/NewTabPageRecyclerView.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/NewTabPageRecyclerView.java |
@@ -195,11 +195,11 @@ int calculateBottomSpacing() { |
return 0; |
} |
- ViewHolder spacer = findBottomSpacer(); |
+ ViewHolder lastContentItem = findLastContentItem(); |
ViewHolder aboveTheFold = findViewHolderForAdapterPosition(aboveTheFoldPosition); |
int bottomSpacing = getHeight() - mToolbarHeight; |
- if (spacer == null || aboveTheFold == null) { |
+ if (lastContentItem == null || aboveTheFold == null) { |
// This can happen in several cases, where some elements are not visible and the |
// RecyclerView didn't already attach them. We handle it by just adding space to make |
// sure that we never run out and force the UI to jump around and get stuck in a |
@@ -214,9 +214,10 @@ int calculateBottomSpacing() { |
Log.w(TAG, "The RecyclerView items are not attached, can't determine the content " |
+ "height: snap=%s, spacer=%s. Using full height: %d ", |
- aboveTheFold, spacer, bottomSpacing); |
+ aboveTheFold, lastContentItem, bottomSpacing); |
} else { |
- int contentHeight = spacer.itemView.getTop() - aboveTheFold.itemView.getBottom(); |
+ int contentHeight = |
+ lastContentItem.itemView.getBottom() - aboveTheFold.itemView.getBottom(); |
bottomSpacing -= contentHeight - mCompensationHeight; |
} |
@@ -323,6 +324,13 @@ private ViewHolder findBottomSpacer() { |
return findViewHolderForAdapterPosition(position); |
} |
+ private ViewHolder findLastContentItem() { |
+ int position = getNewTabPageAdapter().getLastContentItemPosition(); |
+ if (position == RecyclerView.NO_POSITION) return null; |
+ |
+ return findViewHolderForAdapterPosition(position); |
+ } |
+ |
/** |
* Finds the above the fold view. |
* @return The view for above the fold or null, if it is not present. |