国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

彈性

2019-11-09 15:16:09
字體:
來源:轉載
供稿:網友
package com.hou.mask;import android.content.Context;import android.graphics.Rect;import android.support.v4.view.MotionEventCompat;import android.util.AttributeSet;import android.util.Log;import android.view.MotionEvent;import android.view.View;import android.view.ViewConfiguration;import android.view.animation.TranslateAnimation;import android.widget.ScrollView;/** * */public class ReboundScrollView extends ScrollView { PRivate static final String TAG = "MaskScrollView"; private static final int INVALID_POINTER = -1; private static final int FACTOR = 2;//因子,阻尼系數 private View childView; private int mActivePointerId; private float mLastMotionY; private float lastDeltaY; private Rect normal = new Rect(); private int mTouchSlop; private static final int ALL = 0; private static final int NONE = 1; private static final int TOP = 2; private static final int BOTTOM = 3; private int elasticity; public ReboundScrollView(Context context) { this(context, null); } public ReboundScrollView(Context context, AttributeSet attrs) { this(context, attrs, 0); } public ReboundScrollView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); final ViewConfiguration configuration = ViewConfiguration.get(context); mTouchSlop = configuration.getScaledTouchSlop(); elasticity = ALL; } @Override protected void onFinishInflate() { super.onFinishInflate(); childView = getChildAt(0); } @Override public boolean onInterceptTouchEvent(MotionEvent ev) { int action = ev.getAction(); if (action == MotionEvent.ACTION_MOVE && Math.abs(ev.getY() - mLastMotionY) > mTouchSlop) { return true; } else if (action == MotionEvent.ACTION_DOWN) { if (getChildCount() == 0) { return false; } mLastMotionY = ev.getY(); mActivePointerId = ev.getPointerId(0); lastDeltaY = 0; } return super.onInterceptTouchEvent(ev); } @Override public boolean onTouchEvent(MotionEvent ev) { int actionMasked = MotionEventCompat.getActionMasked(ev); switch (actionMasked) { case MotionEvent.ACTION_DOWN: if (getChildCount() == 0) { return false; } mLastMotionY = ev.getY(); mActivePointerId = ev.getPointerId(0); lastDeltaY = 0; break; case MotionEvent.ACTION_MOVE: int activePointerIndex = ev.findPointerIndex(mActivePointerId); if (activePointerIndex == -1) { Log.e(TAG, "Invalid pointerId=" + mActivePointerId + " in onTouchEvent"); break; } final float y = ev.getY(activePointerIndex); float deltaY = mLastMotionY - y; //<0只是上邊有彈性,>0只是下邊有彈性,不加上下都有 if (elasticity == ALL || elasticity == TOP && deltaY < 0 || elasticity == BOTTOM && deltaY > 0) { if (normal.isEmpty()) { //記錄原始位置,用來恢復 normal.set(childView.getLeft(), childView.getTop(), childView.getRight(), childView.getBottom()); } int offsetY = (int) ((lastDeltaY - deltaY) / FACTOR); childView.layout(childView.getLeft(), childView.getTop() + offsetY, childView.getRight(), childView.getBottom() + offsetY); lastDeltaY = deltaY; } break; case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: animateToBack(); mActivePointerId = INVALID_POINTER; break; case MotionEvent.ACTION_POINTER_DOWN: int index = ev.getActionIndex(); mLastMotionY = ev.getY(index); mActivePointerId = ev.getPointerId(index); lastDeltaY = 0; break; case MotionEvent.ACTION_POINTER_UP: onSecondaryPointerUp(ev); mLastMotionY = ev.getY(ev.findPointerIndex(mActivePointerId)); final float upY = ev.getY(ev.findPointerIndex(mActivePointerId)); lastDeltaY = mLastMotionY - upY; break; } return super.onTouchEvent(ev); } private void animateToBack() { TranslateAnimation animation = new TranslateAnimation(0, 0, childView.getTop() - getPaddingTop(), normal.top - getPaddingTop()); animation.setDuration(200); childView.startAnimation(animation); childView.offsetTopAndBottom(normal.top - childView.getTop()); normal.setEmpty(); } private void onSecondaryPointerUp(MotionEvent ev) { final int pointerIndex = (ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT; final int pointerId = ev.getPointerId(pointerIndex); if (pointerId == mActivePointerId) { final int newPointerIndex = pointerIndex == 0 ? 1 : 0; mLastMotionY = ev.getY(newPointerIndex); mActivePointerId = ev.getPointerId(newPointerIndex); } }}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 达拉特旗| 库车县| 海晏县| 瑞昌市| 广德县| 新泰市| 古蔺县| 洛宁县| 莆田市| 固安县| 顺昌县| 临猗县| 鲁山县| 桂东县| 永州市| 河津市| 乐平市| 呼图壁县| 绥棱县| 巴里| 黄大仙区| 阿拉善右旗| 东阿县| 甘德县| 仪陇县| 黄梅县| 涿鹿县| 河池市| 定州市| 灯塔市| 义马市| 安乡县| 寻乌县| 平和县| 侯马市| 连平县| 隆化县| 铜鼓县| 松阳县| 津市市| 宁安市|