Android中Webview的向上滑动和向下滑动动画

发布于 2024-12-20 02:09:02 字数 272 浏览 1 评论 0原文

我的列表中有一个章节列表。当用户选择一个章节时,它会展开并在该章节列表中显示子主题。当用户选择特定子主题时,其内容将加载到新屏幕上的 Web 视图中。一切都做得很好。但我想要 webview 上的一些功能。当用户向上滑动 Web 视图时,Web 视图应向上移动,屏幕上应出现一个从下到上的新 Web 视图(在 Web 视图上向上滑动动画)以及下一个子主题内容。当用户向下滑动带有先前子主题内容的 Web 视图时,向下滑动的情况也是如此。

请帮忙 如何在 webview 上提供向上滑动和向下滑动的动画。 谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

耳钉梦 2024-12-27 02:09:02

将动画应用到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>

使用Wbeview startAnimation方法

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

梦里南柯 2024-12-27 02:09:02

请在您的活动中实现 OnGestureListener

并使用以下代码

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 方法将处理 x 方向的触摸事件,并且您也可以使其在 y 轴上工作

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文