Slide up and Slide down animation on Webview in Android

99封情书 提交于 2019-12-06 02:17:08

问题


i have a list of chapters in a list.when user selects a chapter it get expanded and sub topics in that chapter lists. when user select the particular sub topic its contents get loaded in webview on new screen. its all done fine. But i want some functionality on webview. When user slide up the webview, webview should move up side and a new webview from bottom to upside should appear on screen (slide up animation on webview) with next subtopics contents. same in case of slide down when user slides down web view with previous subtopics contents.

Please help how to provide slide up and slide down animation on webview. Thanks


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/8428738/slide-up-and-slide-down-animation-on-webview-in-android

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