使用nineoldandroid.jar包 简单实现全屏滑动


下面代码中ViewHelper需要用到nineoldandroid.jar。




@Override
public boolean onTouchEvent(MotionEvent event) {

    int x =(int) event.getRawX();
    int y =(int) event.getRawY();
    switch (event.getAction()){
        case MotionEvent.ACTION_DOWN:
            break;
        case MotionEvent.ACTION_MOVE:
            int deltaX=x-mLastx;
            int deltaY=y-mLasty;
            int translationX= (int)ViewHelper.getTranslationX(this)+deltaX;
            int translationY= (int)ViewHelper.getTranslationY(this)+deltaY;
            ViewHelper.setTranslationX(this,translationX);
            ViewHelper.setTranslationY(this,translationY);
            break;
        case MotionEvent.ACTION_UP:
            break;
        default:
            break;
    }
    mLastx=x;
    mLasty=y;
    return true;
}




猜你喜欢

转载自blog.csdn.net/zanshiyonghuming/article/details/53765410

相关文章