} catch (NoSuchMethodException e) {
// For Android < 2.0
historicalY = (int) (ev.getHistoricalY(h));
} catch (IllegalArgumentException e) {
throw e;
} catch (IllegalAccessException e) {
System.err.println("unexpected " + e);
} catch (InvocationTargetException e) {
System.err.println("unexpected " + e);
}
// Calculate the padding to apply, we divide by 1.7 to
// simulate a more resistant effect during pull.
int topPadding = (int) (((historicalY - mLastMotionY)
- mRefreshViewHeight) / 1.7);
// 设置上、下、左、右四个位置的间隙间隙
mRefreshHeaderView.setPadding(
mRefreshHeaderView.getPaddingLeft(),
topPadding,
mRefreshHeaderView.getPaddingRight(),
mRefreshHeaderView.getPaddingBottom());
}
}
}
}
/**
-
Sets the header padding back to original size.
-
设置头部填充会原始大小
*/
private void resetHeaderPadding() {
mRefreshHeaderView.setPadding(
mRefreshHeaderView.getPaddingLeft(),
mRefreshOriginalTopPadding,
mRefreshHeaderView.getPaddingRight(),
mRefreshHeaderView.getPaddingBottom());
}
/**
-
Resets the header to the original state.
-
重新设置头部为原始状态
*/
private void resetHeader() {
if (mRefreshState != TAP_TO_REFRESH) {
mRefreshState = TAP_TO_REFRESH;
resetHeaderPadding();
// Set refresh view text to the pull label
mRefreshViewText.setText(R.string.pull_to_refresh_tap_label);
// Replace refresh drawable with arrow drawable
mRefreshViewImage.setImageResource(R.drawable.ic_pulltorefresh_arrow);
// Clear the full rotation animation
mRefreshViewImage.clearAnimation();
// Hide progress bar and arrow.
mRefreshViewImage.setVisibility(View.GONE);
mRefreshViewProgress.setVisibility(View.GONE);
}
}
/**
- 重设ListView尾部视图为初始状态
*/
private void resetFooter() {
if(mLoadState != TAP_TO_LOADMORE) {
mLoadState = TAP_TO_LOADMORE;
// 进度条设置为不可见
mLoadMoreProgress.setVisibility(View.GONE);
// 按钮的文本替换为“加载更多”
mLoadMoreText.setText(R.string.loadmore_label);
}
}
/**
-
测量视图的大小
-
@param child
*/
private void measureView(View child) {
ViewGroup.LayoutParams p = child.getLayoutParams();
if (p == null) {
p = new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
}
int childWidthSpec = ViewGroup.getChildMeasureSpec(0,
0 + 0, p.width);
int lpHeight = p.height;
int childHeightSpec;
if (lpHeight > 0) {
childHeightSpec = MeasureSpec.makeMeasureSpec(lpHeight, MeasureSpec.EXACTLY);
} else {
childHeightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
}
child.measure(childWidthSpec, childHeightSpec);
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
// When the refresh view is completely visible, change the text to say
// “Release to refresh…” and flip the arrow drawable.
if (mCurrentScrollState == SCROLL_STATE_TOUCH_SCROLL
&&am