在Android上,用于获取启动屏幕向左或向右滚动的Android Api是什么?
在Android上,用于获取启动屏幕向左或向右滚动的Android Api是什么?
class MyView extends View
{
GestureDetector mGestureDetect;
public MyView(Context context)
{
super(context);
mGestureDetect = new GestureDetector(new SimpleOnGestureListener()
{
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
{
//check if the fling was in the direction you were interested in
if(e1.getX() - e2.getX() > 0)
{
//Do something here
}
//fast enough?
if(velocityX > 50)
{
//etc etc
}
return true;
}
}
}
public boolean onTouchEvent(MotionEvent ev)
{
mGestureDetector.onTocuhEvent(ev);
return true;
}
}
所有源代码仓库都在这里,供您浏览:
在较新版本中,它使用ViewGroup.onInterceptTouchEvent和View.onTouchEvent来捕获拖动事件,并根据从触摸开始的移动量进行手动计算。
实际上的移动只是通过View.scrollBy来完成。
您正在寻找GestureLibraries类。在此处阅读更多相关信息here。
我自己没有使用过这个,所以无法给您更多信息,但这些也可能会有用: