首页 > 系统 > iOS > 正文

android仿ios弹性页

2019-11-11 04:45:55
字体:
来源:转载
供稿:网友
public class Drag extends LinearLayout {    PRivate ViewDragHelper mDraw;    private Point mPoint = new Point();    public Drag(Context context, AttributeSet attrs) {        super(context, attrs);        mDraw = ViewDragHelper.create(this, 1.0f, new ViewDragHelper.Callback() {            @Override            public boolean tryCaptureView(View child, int pointerId) {                return true;            }            @Override            public int clampViewPositionHorizontal(View child, int left, int dx) {                int boundaryLeft = getPaddingLeft();                int boundaryRight = getWidth() - child.getWidth() - getPaddingRight();                left = Math.min(Math.max(left, boundaryLeft), boundaryRight);                return left;            }            @Override            public int clampViewPositionVertical(View child, int top, int dy) {                Log.e("zxc", "top-------->" + top);                //垂直下拉弹性                if (top == 0) {                    top = 0;                }                if (top > 300) {                    top = 300;                }              //垂直上拉弹性                if (top < 0){                    if (top < -300){                        top = -300;                    }                }                return top;            }            //手指释放的时候回调            @Override            public void onViewReleased(View releasedChild, float xvel, float yvel) {                mDraw.settleCapturedViewAt(0,0);                invalidate();            }        });    }    @Override    public void computeScroll()    {        if(mDraw.continueSettling(true))        {            invalidate();        }    }    @Override    protected void onLayout(boolean changed, int l, int t, int r, int b) {        super.onLayout(changed, l, t, r, b);    }    @Override    public boolean onInterceptTouchEvent(MotionEvent ev) {        return mDraw.shouldInterceptTouchEvent(ev);    }    @Override    public boolean onTouchEvent(MotionEvent event) {        mDraw.processTouchEvent(event);        return true;    }}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表