在时间之廊滚动一个图像 [英] Gallery scroll one image at a time

查看:101
本文介绍了在时间之廊滚动一个图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使一个画廊控制滚动一个图像的时间?还有什么是对这些映像进行连续循环的好方法?我试着重写onFling,不能在所有的工作。

此图像移动一定的距离,但并没有真正实现真正的分页。

  @覆盖
        公共布尔onFling(MotionEvent E1,E2 MotionEvent,浮velocityX,浮velocityY){

          //返回super.onFling(E1,E2,velocityX,velocityY);
            INT KEVENT;
              如果(isScrollingLeft(E1,E2)){//检查滚动左
                KEVENT = KeyEvent.KEY code_DPAD_LEFT;
              }
              其他{//否则滚动权
                KEVENT = KeyEvent.KEY code_DPAD_RIGHT;
              }
              的onkeydown(KEVENT,NULL);
              返回true;
        }
        私人布尔isScrollingLeft(MotionEvent E1,E2 MotionEvent){
              返回e2.getX()> e1.getX();
            }
 

解决方案

我创造了新的控制,把它称为CustomGallery和画廊扩展它。在自定义图库我把以下内容:

  @覆盖
       公共布尔onFling(MotionEvent E1,E2 MotionEvent,浮velocityX,浮velocityY){
         返回super.onFling(E1,E2,0,velocityY);
       }
 

在我的活动我使用CustomGallery而非画廊。这个工程。有一件事,我们从2.2移到2.3(姜饼)。对我来说,当我试图重写onFling之前,它没有工作。因此,我怀疑这还必须是与操作系统的版本。

how to make a gallery control to scroll one image at a time? Also what is a good way of making a continuous loop of those images? I tried overriding onFling, does not work at all.

This moves image certain distance but does not really implement "true paging".

@Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {

          //  return super.onFling(e1, e2, velocityX, velocityY);
            int kEvent;
              if(isScrollingLeft(e1, e2)){ //Check if scrolling left
                kEvent = KeyEvent.KEYCODE_DPAD_LEFT;
              }
              else{ //Otherwise scrolling right
                kEvent = KeyEvent.KEYCODE_DPAD_RIGHT;
              }
              onKeyDown(kEvent, null);
              return true;  
        }
        private boolean isScrollingLeft(MotionEvent e1, MotionEvent e2){
              return e2.getX() > e1.getX();
            }

解决方案

I created new control, called it CustomGallery and extended it from Gallery. In Custom Gallery I placed the following:

@Override
       public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
         return super.onFling(e1, e2, 0, velocityY);
       }

In my activity I am using CustomGallery instead of Gallery. This works. One thing, we moved from 2.2 to 2.3 (gingerbread). It didn't work for me before when I tried to override onFling. So I am suspecting this also have something to do with the version of OS.

这篇关于在时间之廊滚动一个图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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