Android UI--自定义ListView(实现下拉刷新+加载更多)

} 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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值