Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use GridView verticalSpacing when calculating the grid height #419

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.antonyt.infiniteviewpager;

import android.content.Context;
import android.os.Build;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.GridView;

import java.util.ArrayList;

Expand Down Expand Up @@ -41,6 +43,7 @@ public class InfiniteViewPager extends ViewPager {
* Use internally to decide height of the calendar
*/
private int rowHeight = 0;
private int rowSpacing = 0;

// ******* Setter and getters *********
public boolean isEnabled() {
Expand Down Expand Up @@ -130,20 +133,28 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));

rowHeight = firstChild.getMeasuredHeight();

// Consider gridview vertical spacing (Available on API >= 16 only)
if (firstChild instanceof GridView && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
rowSpacing = ((GridView)firstChild).getVerticalSpacing();
}
}

// Calculate height of the calendar
int calHeight;

// If fit 6 weeks, we need 6 rows
if (sixWeeksInCalendar) {
calHeight = rowHeight * 6;
calHeight = (rowHeight * 6) + (rowSpacing * 5);
} else { // Otherwise we return correct number of rows
calHeight = rowHeight * rows;
calHeight = (rowHeight * rows) + (rowSpacing * (rows-1));
}

// Prevent small vertical scroll (if we couldnt find vertical spacing)
if (rowSpacing == 0) {
calHeight -= 12;
}

// Prevent small vertical scroll
calHeight -= 12;
heightMeasureSpec = MeasureSpec.makeMeasureSpec(calHeight,
MeasureSpec.EXACTLY);

Expand Down