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

pin header view #236

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
23 changes: 22 additions & 1 deletion ptr-lib/src/in/srain/cube/views/ptr/PtrFrameLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class PtrFrameLayout extends ViewGroup {
private final static byte FLAG_AUTO_REFRESH_BUT_LATER = 0x01 << 1;
private final static byte FLAG_ENABLE_NEXT_PTR_AT_ONCE = 0x01 << 2;
private final static byte FLAG_PIN_CONTENT = 0x01 << 3;
private final static byte FLAG_PIN_HEADER = 0x01 << 4;
private final static byte MASK_AUTO_REFRESH = 0x03;
protected View mContent;
// optional config for define header and content in xml file
Expand Down Expand Up @@ -424,9 +425,14 @@ private void updatePos(int change) {
if (DEBUG) {
PtrCLog.v(LOG_TAG, "updatePos: change: %s, current: %s last: %s, top: %s, headerHeight: %s",
change, mPtrIndicator.getCurrentPosY(), mPtrIndicator.getLastPosY(), mContent.getTop(), mHeaderHeight);
PtrCLog.v(LOG_TAG, "updatePos: headerView: top: %s", mHeaderView.getTop());
}

mHeaderView.offsetTopAndBottom(change);
if (mHeaderView.getTop() <= PtrIndicator.POS_START){
mHeaderView.offsetTopAndBottom(change);
} else if (!isPinHeader()) {
mHeaderView.offsetTopAndBottom(change);
}
if (!isPinContent()) {
mContent.offsetTopAndBottom(change);
}
Expand Down Expand Up @@ -742,6 +748,21 @@ public void setPinContent(boolean pinContent) {
}
}

public boolean isPinHeader() {
return (mFlag & FLAG_PIN_HEADER) > 0;
}

/*
* The header move to visible,will not move when {@param pinHeader} set to true
*/
public void setPinHeader(boolean pinHeader){
if (pinHeader) {
mFlag = mFlag | FLAG_PIN_HEADER;
} else {
mFlag = mFlag & ~FLAG_PIN_HEADER;
}
}

/**
* It's useful when working with viewpager.
*
Expand Down