Slide up and Slide down animation on Webview in Android

不想你离开。 提交于 2019-12-04 05:23:15

Apply animation to webview..

Slide down.xml

<?xml version="1.0" encoding="utf-8"?>

<set xmlns:android="http://schemas.android.com/apk/res/android">

<translate android:fromYDelta="0%p"   
          android:interpolator="@android:anim/accelerate_interpolator"      
    android:toYDelta="100%p" android:duration="2000" />  
</set>

Slide Up.xml

<?xml version="1.0" encoding="utf-8"?>

<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator">

<translate android:fromYDelta="100%" 
                   android:toXDelta="0" 
                   android:duration="1000" />
<alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="500" />
</set>

Use Wbeview startAnimation method

pleas implement OnGestureListener in your activity

and use the following code

detector = new GestureDetector(this, this);
WebView1.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            detector.onTouchEvent(event);
            return true;
        }
    });


@Override
public boolean onDown(MotionEvent e) {
    // TODO Auto-generated method stub
    return false;
}

@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
    float dX = e2.getX() - e1.getX();
    float dY = e1.getY() - e2.getY();
    // check is all completed or return with some condition
    if (Math.abs(dY) < SWIPE_MAX_OFF_PATH && Math.abs(velocityX) >= SWIPE_THRESHOLD_VELOCITY && Math.abs(dX) >= SWIPE_MIN_DISTANCE) {
// logic for left and right
if(dX>0){
}
  elseif(dX<0)
    }   
    return false;
}

@Override
public void onLongPress(MotionEvent e) {
    // TODO Auto-generated method stub

}

@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
    // TODO Auto-generated method stub
    return false;
}

@Override
public void onShowPress(MotionEvent e) {
    // TODO Auto-generated method stub

}

@Override
public boolean onSingleTapUp(MotionEvent e) {
    // TODO Auto-generated method stub
    return false;
}

fling method will handle the touch event if x direction and you can make it work in y axis as well

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!