赞
踩
最近一直比较忙,也没抽出时间来写博客,人一懒就说明都不想做了。
博客如果不能坚持的话,那就没什么意义了,也就废了,最近研究了一下QQ空间动态页面,自己也试着写了一个,现在拿出来分享给大家,好了,废话不多说,切入正题,先看看我们今天要实现功能的效果图:
来看下我们今天要介绍的主角
PullToZoomInListView
github地址如下:https://github.com/matrixxun/PullToZoomInListView
一个下拉放大的空间,这种效果在ios应用中很常见,Android中不少应用也有它的身影,玩过QQ的人都知道,QQ空间动态界面有着这几个功能(下拉刷新,图片放大,上拉加载更多,标题栏渐变,图标变化)
我本着不重复造轮子,在前人的基础上而外添加了些功能
1、添加了一个footer
2、添加了一个监听器,用于监听下拉刷新和上拉加载更多
3、添加了一个判断是否有更多数据的方法
修改后的PullToZoomInListView代码如下:
public class PullToZoomListView extends ListView implements AbsListView.OnScrollListener { private View footerView; private TextView tv_footer_text; private View fl_progress_bar; private boolean isNoMore = false; private boolean isLoad = false; private static final Interpolator sInterpolator = new Interpolator() { public float getInterpolation(float paramAnonymousFloat) { float f = paramAnonymousFloat - 1.0F; return 1.0F + f * (f * (f * (f * f))); } }; int mActivePointerId = -1; private FrameLayout mHeaderContainer; private int mHeaderHeight; public int getmHeaderHeight() { return mHeaderHeight; } /** * 设置头部的高度 * * @param mHeaderHeight */ public void setmHeaderHeight(int mHeaderHeight) { this.mHeaderHeight = mHeaderHeight; AbsListView.LayoutParams lp = new AbsListView.LayoutParams(DensityUtil.dp2px(mContext, AbsListView.LayoutParams.MATCH_PARENT), mHeaderHeight); getHeaderContainer().setLayoutParams(lp); } private ImageView mHeaderImage; float mLastMotionY = -1.0F; float mLastScale = -1.0F; float mMaxScale = -1.0F; private AbsListView.OnScrollListener mOnScrollListener; private ScalingRunnalable mScalingRunnalable; private int mScreenHeight; private ImageView mShadow; private Context mContext; public PullToZoomListView(Context paramContext) { super(paramContext); init(paramContext); mContext = paramContext; } public PullToZoomListView(Context paramContext, AttributeSet paramAttributeSet) { super(paramContext, paramAttributeSet); init(paramContext); mContext = paramContext; } public PullToZoomListView(Context paramContext, AttributeSet paramAttributeSet, int paramInt) { super(paramContext, paramAttributeSet, paramInt); init(paramContext); mContext = paramContext; } private void endScraling() { if (this.mHeaderContainer.getBottom() >= this.mHeaderHeight) Log.d("mmm", "endScraling"); this.mScalingRunnalable.startAnimation(100L); } private void init(Context paramContext) { DisplayMetrics localDisplayMetrics = new DisplayMetrics(); ((Activity) paramContext).getWindowManager().getDefaultDisplay().getMetrics(localDisplayMetrics); this.mScreenHeight = localDisplayMetrics.heightPixels; this.mHeaderContainer = new FrameLayout(paramContext); this.mHeaderImage = new ImageView(paramContext); mHeaderImage.setScaleType(ImageView.ScaleType.CENTER_CROP); int i = localDisplayMetrics.widthPixels; setHeaderViewSize(i, (int) (9.0F * (i / 16.0F))); this.mShadow = new ImageView(paramContext); FrameLayout.LayoutParams localLayoutParams = new FrameLayout.LayoutParams(-1, -2); localLayoutParams.gravity = Gravity.CENTER; this.mShadow.setLayoutParams(localLayoutParams); this.mHeaderContainer.addView(this.mHeaderImage); this.mHeaderContainer.addView(this.mShadow); // addHeaderView(this.mHeaderContainer); footerView = LayoutInflater.from(paramContext).inflate(R.layout.zoomlistview_footer, null); tv_footer_text = (TextView) footerView.findViewById(R.id.tv_footer_text); fl_progress_bar = footerView.findViewById(R.id.fl_progress_bar); //addFooterView addFooterView(footerView); this.mScalingRunnalable = new ScalingRunnalable(); super.setOnScrollListener(this); } private void onSecondaryPointerUp(MotionEvent paramMotionEvent) { int i = (paramMotionEvent.getAction()) >> 8; if (paramMotionEvent.getPointerId(i) == this.mActivePointerId) if (i != 0) { this.mLastMotionY = paramMotionEvent.getY(0); this.mActivePointerId = paramMotionEvent.getPointerId(0); return; } } private void reset() { this.mActivePointerId = -1; this.mLastMotionY = -1.0F; this.mMaxScale = -1.0F; this.mLastScale = -1.0F; } public ImageView getHeaderView() { return this.mHeaderImage; } public FrameLayout getHeaderContainer() { return mHeaderContainer; } public void setHeaderView() { addHeaderView(this.mHeaderContainer); } /* * public boolean onInterceptTouchEvent(MotionEvent ev) { * * final int action = ev.getAction() & MotionEvent.ACTION_MASK; float * mInitialMotionX= 0; float mLastMotionX= 0; * * float mInitialMotionY= 0; float mLastMotionY = 0; * * boolean isIntercept=false; switch (action) { case * MotionEvent.ACTION_DOWN: * * mLastMotionY=ev.getY(); break; * * case MotionEvent.ACTION_MOVE: mInitialMotionY = ev.getY(); * * if(Math.abs(mInitialMotionY-mLastMotionY)>50) { isIntercept=true; } * break; * * } * * return isIntercept; } */ protected void onLayout(boolean paramBoolean, int paramInt1, int paramInt2, int paramInt3, int paramInt4) {
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。