多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國內(nèi)最全I(xiàn)T社區(qū)平臺 聯(lián)系我們 | 收藏本站
阿里云優(yōu)惠2
您當(dāng)前位置:首頁 > php開源 > 綜合技術(shù) > Android 自定義控件PullToZoomListView

Android 自定義控件PullToZoomListView

來源:程序員人生   發(fā)布時間:2014-12-14 08:47:17 閱讀次數(shù):4297次

今網(wǎng)上發(fā)現(xiàn)開源控件PullToZoomListView :https://github.com/matrixxun/PullToZoomInListView

效果圖:




import android.app.Activity; import android.content.Context; import android.os.SystemClock; import android.util.AttributeSet; import android.util.DisplayMetrics; import android.util.Log; import android.view.MotionEvent; import android.view.ViewGroup; import android.view.animation.Interpolator; import android.widget.AbsListView; import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.ListView; public class PullToZoomListView extends ListView implements AbsListView.OnScrollListener { @SuppressWarnings("unused") private static final int INVALID_VALUE = ⑴; @SuppressWarnings("unused") private static final String TAG = "PullToZoomListView"; 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 = ⑴; private FrameLayout mHeaderContainer; private int mHeaderHeight; private ImageView mHeaderImage; float mLastMotionY = ⑴.0F; float mLastScale = ⑴.0F; float mMaxScale = ⑴.0F; private AbsListView.OnScrollListener mOnScrollListener; private ScalingRunnalable mScalingRunnalable; private int mScreenHeight; private ImageView mShadow; public PullToZoomListView(Context paramContext) { super(paramContext); init(paramContext); } public PullToZoomListView(Context paramContext, AttributeSet paramAttributeSet) { super(paramContext, paramAttributeSet); init(paramContext); } public PullToZoomListView(Context paramContext, AttributeSet paramAttributeSet, int paramInt) { super(paramContext, paramAttributeSet, paramInt); init(paramContext); } private void endScraling() { if (this.mHeaderContainer.getBottom() >= this.mHeaderHeight) Log.d("mmm", "endScraling"); this.mScalingRunnalable.startAnimation(200L); } 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); int i = localDisplayMetrics.widthPixels; setHeaderViewSize(i, (int) (9.0F * (i / 16.0F))); this.mShadow = new ImageView(paramContext); FrameLayout.LayoutParams localLayoutParams = new FrameLayout.LayoutParams( ⑴, ⑵); localLayoutParams.gravity = 80; this.mShadow.setLayoutParams(localLayoutParams); this.mHeaderContainer.addView(this.mHeaderImage); this.mHeaderContainer.addView(this.mShadow); addHeaderView(this.mHeaderContainer); 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) { int j = 1; this.mLastMotionY = paramMotionEvent.getY(0); this.mActivePointerId = paramMotionEvent.getPointerId(0); return; } } private void reset() { this.mActivePointerId = ⑴; this.mLastMotionY = ⑴.0F; this.mMaxScale = ⑴.0F; this.mLastScale = ⑴.0F; } public ImageView getHeaderView() { return this.mHeaderImage; } public boolean onInterceptTouchEvent(MotionEvent paramMotionEvent) { return super.onInterceptTouchEvent(paramMotionEvent); } protected void onLayout(boolean paramBoolean, int paramInt1, int paramInt2, int paramInt3, int paramInt4) { super.onLayout(paramBoolean, paramInt1, paramInt2, paramInt3, paramInt4); if (this.mHeaderHeight == 0) this.mHeaderHeight = this.mHeaderContainer.getHeight(); } @Override public void onScroll(AbsListView paramAbsListView, int paramInt1, int paramInt2, int paramInt3) { Log.d("mmm", "onScroll"); float f = this.mHeaderHeight - this.mHeaderContainer.getBottom(); Log.d("mmm", "f|" + f); if ((f > 0.0F) && (f < this.mHeaderHeight)) { Log.d("mmm", "1"); int i = (int) (0.65D * f); this.mHeaderImage.scrollTo(0, -i); } else if (this.mHeaderImage.getScrollY() != 0) { Log.d("mmm", "2"); this.mHeaderImage.scrollTo(0, 0); } if (this.mOnScrollListener != null) { this.mOnScrollListener.onScroll(paramAbsListView, paramInt1, paramInt2, paramInt3); } } public void onScrollStateChanged(AbsListView paramAbsListView, int paramInt) { if (this.mOnScrollListener != null) this.mOnScrollListener.onScrollStateChanged(paramAbsListView, paramInt); } public boolean onTouchEvent(MotionEvent paramMotionEvent) { Log.d("mmm", "" + (0xFF & paramMotionEvent.getAction())); switch (0xFF & paramMotionEvent.getAction()) { case 4: case 0: if (!this.mScalingRunnalable.mIsFinished) { this.mScalingRunnalable.abortAnimation(); } this.mLastMotionY = paramMotionEvent.getY(); this.mActivePointerId = paramMotionEvent.getPointerId(0); this.mMaxScale = (this.mScreenHeight / this.mHeaderHeight); this.mLastScale = (this.mHeaderContainer.getBottom() / this.mHeaderHeight); break; case 2: Log.d("mmm", "mActivePointerId" + mActivePointerId); int j = paramMotionEvent.findPointerIndex(this.mActivePointerId); if (j == ⑴) { Log.e("PullToZoomListView", "Invalid pointerId=" + this.mActivePointerId + " in onTouchEvent"); } else { if (this.mLastMotionY == ⑴.0F) this.mLastMotionY = paramMotionEvent.getY(j); if (this.mHeaderContainer.getBottom() >= this.mHeaderHeight) { ViewGroup.LayoutParams localLayoutParams = this.mHeaderContainer .getLayoutParams(); float f = ((paramMotionEvent.getY(j) - this.mLastMotionY + this.mHeaderContainer .getBottom()) / this.mHeaderHeight - this.mLastScale) / 2.0F + this.mLastScale; if ((this.mLastScale <= 1.0D) && (f < this.mLastScale)) { localLayoutParams.height = this.mHeaderHeight; this.mHeaderContainer .setLayoutParams(localLayoutParams); return super.onTouchEvent(paramMotionEvent); } this.mLastScale = Math.min(Math.max(f, 1.0F), this.mMaxScale); localLayoutParams.height = ((int) (this.mHeaderHeight * this.mLastScale)); if (localLayoutParams.height < this.mScreenHeight) this.mHeaderContainer .setLayoutParams(localLayoutParams); this.mLastMotionY = paramMotionEvent.getY(j); return true; } this.mLastMotionY = paramMotionEvent.getY(j); } break; case 1: reset(); endScraling(); break; case 3: int i = paramMotionEvent.getActionIndex(); this.mLastMotionY = paramMotionEvent.getY(i); this.mActivePointerId = paramMotionEvent.getPointerId(i); break; case 5: onSecondaryPointerUp(paramMotionEvent); this.mLastMotionY = paramMotionEvent.getY(paramMotionEvent .findPointerIndex(this.mActivePointerId)); break; case 6: } return super.onTouchEvent(paramMotionEvent); } public void setHeaderViewSize(int paramInt1, int paramInt2) { Object localObject = this.mHeaderContainer.getLayoutParams(); if (localObject == null) localObject = new AbsListView.LayoutParams(paramInt1, paramInt2); ((ViewGroup.LayoutParams) localObject).width = paramInt1; ((ViewGroup.LayoutParams) localObject).height = paramInt2; this.mHeaderContainer .setLayoutParams((ViewGroup.LayoutParams) localObject); this.mHeaderHeight = paramInt2; } public void setOnScrollListener( AbsListView.OnScrollListener paramOnScrollListener) { this.mOnScrollListener = paramOnScrollListener; } public void setShadow(int paramInt) { this.mShadow.setBackgroundResource(paramInt); } class ScalingRunnalable implements Runnable { long mDuration; boolean mIsFinished = true; float mScale; long mStartTime; ScalingRunnalable() { } public void abortAnimation() { this.mIsFinished = true; } public boolean isFinished() { return this.mIsFinished; } public void run() { float f2; ViewGroup.LayoutParams localLayoutParams; if ((!this.mIsFinished) && (this.mScale > 1.0D)) { float f1 = ((float) SystemClock.currentThreadTimeMillis() - (float) this.mStartTime) / (float) this.mDuration; f2 = this.mScale - (this.mScale - 1.0F) * PullToZoomListView.sInterpolator.getInterpolation(f1); localLayoutParams = PullToZoomListView.this.mHeaderContainer .getLayoutParams(); if (f2 > 1.0F) { Log.d("mmm", "f2>1.0"); localLayoutParams.height = PullToZoomListView.this.mHeaderHeight; ; localLayoutParams.height = ((int) (f2 * PullToZoomListView.this.mHeaderHeight)); PullToZoomListView.this.mHeaderContainer .setLayoutParams(localLayoutParams); PullToZoomListView.this.post(this); return; } this.mIsFinished = true; } } public void startAnimation(long paramLong) { this.mStartTime = SystemClock.currentThreadTimeMillis(); this.mDuration = paramLong; this.mScale = ((float) (PullToZoomListView.this.mHeaderContainer .getBottom()) / PullToZoomListView.this.mHeaderHeight); this.mIsFinished = false; PullToZoomListView.this.post(this); } } }
使用實例:


listView = (PullToZoomListView)findViewById(R.id.listview); adapterData = new String[] { "Activity","Service","Content Provider","Intent","BroadcastReceiver","ADT","Sqlite3","HttpClient","DDMS","Android Studio","Fragment","Loader" }; listView.setAdapter(new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1, adapterData)); listView.getHeaderView().setImageResource(R.drawable.splash01); listView.getHeaderView().setScaleType(ImageView.ScaleType.CENTER_CROP);



生活不易,碼農(nóng)辛苦
如果您覺得本網(wǎng)站對您的學(xué)習(xí)有所幫助,可以手機(jī)掃描二維碼進(jìn)行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關(guān)閉
程序員人生
主站蜘蛛池模板: 国产午夜精品不卡视频 | 欧美孕交videosfree另类 | 精品久久久久久中文字幕女 | 伊人精品视频在线观看 | 有码在线视频 | 黑人xxxx videos hd | 久久精品国产免费高清 | 最好免费高清视频在线看 | 久久精品9 | 日本护士xxxxx极品 | 福利视频一区二区 | 国产v综合v亚洲欧美大另类 | 在线观看中文字幕 | 国内自拍成人网在线视频 | 欧美一级毛片大片免费播放 | 日本护士毛片在线视频 | 亚欧中文字幕 | 影音先锋 色天使 | 韩国欧美 | 九操网 | 女bbbbxxxx另类亚洲 | 久久综合一区二区三区 | 网红毛片 | 国内精品久久久久影院中国 | 精品久久久久久中文字幕女 | 亚洲jizzjizz妇女 | 国产日韩视频在线观看 | www.99爱| 一区二三区国产 | 黑人一区二区三区中文字幕 | 久久久久久综合成人精品 | 久久精品免观看国产成人 | 国产丰满主播丝袜勾搭秀 | 欧美精品一国产成人性影视 | 免费大片在线观看www | 亚洲 中文 欧美 日韩 在线人 | 亚洲精品中文字幕乱码三区 | 在线观看亚洲网站 | 91视频一区二区 | 茄子成视频片在线观看 | 亚洲精品久久久久久久久久久网站 |