当前位置: 移动技术网 > 移动技术>移动开发>Android > Android编程实现Gallery中每次滑动只显示一页的方法

Android编程实现Gallery中每次滑动只显示一页的方法

2019年07月24日  | 移动技术网移动技术  | 我要评论

本文实例讲述了android编程实现gallery中每次滑动只显示一页的方法。分享给大家供大家参考,具体如下:

import android.content.context;
import android.util.attributeset;
import android.view.keyevent;
import android.view.motionevent;
import android.widget.gallery;
public class detialgallery extends gallery {
  public detialgallery(context context ,attributeset attrset) {
   super(context,attrset);
   // todo auto-generated constructor stub
  }
  private boolean isscrollingleft(motionevent e1, motionevent e2)
  {
   return e2.getx() > e1.getx();
  }
  @override
  public boolean onfling(motionevent e1, motionevent e2, float velocityx, float velocityy) {
  // todo auto-generated method stub
  // return super.onfling(e1, e2, 0, velocityy);
  //方法一:只去除翻页惯性
  // return false;
  //方法二:只去除翻页惯性 注:没有被注释掉的代码实现了开始说的2种效果。
  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;
 }
}

希望本文所述对大家android程序设计有所帮助。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网