在库中移除刷卡效果从顶部android中底 [英] Remove swipe effect in gallery from top to bottom in android

查看:84
本文介绍了在库中移除刷卡效果从顶部android中底的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开发了一个自定义的画廊,并覆盖上一扔方法,它轻扫一个图像在time.It工作,但问题是,当我刷卡上下,反之亦然图像被偷走,因此变化。

下面是我的code

 公共类mygallery扩展库{公共mygallery(上下文CTX,AttributeSet中的attrSet)根据{
    超(CTX,attrSet)根据;}私人布尔isScrollingLeft(MotionEvent E1,E2 MotionEvent){
    返回e2.getX()> e1.getX();
}私人布尔isScrollingRight(MotionEvent E1,E2 MotionEvent){
    返回e2.getX()&下; e1.getX();}@覆盖
公共布尔onFling(MotionEvent E1,E2 MotionEvent,浮velocityX,
        浮动velocityY){
    INT KEVENT = 0;
    如果(isScrollingLeft(E1,E2)){//检查是否向左滚动
        KEVENT = KeyEvent.KEY code_DPAD_LEFT;
    }否则如果(isScrollingRight(E1,E2)){//否则滚动右
        KEVENT = KeyEvent.KEY code_DPAD_RIGHT;
    }
    的onkeydown(KEVENT,NULL);
    返回true;
}

}

我怎样才能摆脱图像(从上到下,从下到上)的刷卡的。


解决方案

  @覆盖
公共布尔onFling(MotionEvent E1,E2 MotionEvent,浮velocityX,
        浮动velocityY){
    如果(Math.abs(velocityX)GT; Math.abs(velocityY))
    {
        //这是一个水平一扔
        //在这里做你的操作
    }
    其他
        //这是一个垂直的一扔
 }

I have developed a custom gallery and override the on-fling method in it to swipe one image at a time.It worked, but the problem is when i swipe from top to bottom or vice-versa the image gets swiped and hence changes.

Below is my code

public class mygallery extends Gallery {

public mygallery(Context ctx, AttributeSet attrSet) {
    super(ctx, attrSet);

}

private boolean isScrollingLeft(MotionEvent e1, MotionEvent e2) {
    return e2.getX() > e1.getX();
}

private boolean isScrollingRight(MotionEvent e1, MotionEvent e2){
    return e2.getX() < e1.getX();

}



@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
        float velocityY) {
    int kEvent=0;
    if (isScrollingLeft(e1, e2)) { // Check if scrolling left
        kEvent = KeyEvent.KEYCODE_DPAD_LEFT;
    } else if(isScrollingRight(e1, e2)) { // Otherwise scrolling right
        kEvent = KeyEvent.KEYCODE_DPAD_RIGHT;
    } 
    onKeyDown(kEvent, null);
    return true;
}

}

How can i get rid of swiping of images(top to bottom,bottom to top).

解决方案

@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
        float velocityY) {
    if (Math.abs(velocityX) > Math.abs(velocityY))
    {
        // This is an horizontal fling
        // Do your operation here
    }     
    else
        // This is an vertical fling
 }

这篇关于在库中移除刷卡效果从顶部android中底的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆