我已经在某种程度上滑动了工作,但我在屏幕上有一系列的文本视图和微调器,看起来如果我不直接划过它们中的一个而只是在它们中的两个之间它没有好好接受它。总的来说,我认为它不会像iPhone上发生的那样好,我想知道是否有人可以批评我的代码并帮助我优化它。
我正在初始化GesureDectector和GestureListener。这是GestureListener类:
public class GestureListener : Java.Lang.Object, GestureDetector.IOnGestureListener
{
private static int SWIPE_MAX_OFF_PATH = 250;
private static int SWIPE_MIN_DISTANCE = 50;
private static int SWIPE_THRESHOLD_VELOCITY = 200;
private View view;
private Activity act;
public GestureListener(View _view, Activity _act)
{
view = _view;
act = _act;
}
public bool OnDown( MotionEvent e )
{
return true;
}
public bool OnFling( MotionEvent e1, MotionEvent e2, float velocityX, float velocityY )
{
if ( Math.Abs( e1.GetY() - e2.GetY() ) > SWIPE_MAX_OFF_PATH ){
return false;
}
if ( e1.GetX() - e2.GetX() > SWIPE_MIN_DISTANCE && Math.Abs( velocityX ) > SWIPE_THRESHOLD_VELOCITY ){
HandleLeft();
}else if ( e2.GetX() - e1.GetX() > SWIPE_MIN_DISTANCE && Math.Abs( velocityX ) > SWIPE_THRESHOLD_VELOCITY ){
HandleRight();
}
return false;
}
public void OnLongPress( MotionEvent e )
{
}
public bool OnScroll( MotionEvent e1, MotionEvent e2, float distanceX, float distanceY )
{
return true;
}
public void OnShowPress( MotionEvent e )
{
}
public bool OnSingleTapUp( MotionEvent e )
{
return true;
}
private void HandleLeft(){
Male currActivity = (Male)act;
currActivity.GetStrings("Female");
}
private void HandleRight(){
Male currActivity = (Male)act;
currActivity.GetStrings("Results");
}
}
我在OnTouch活动中使用它:
public bool OnTouch(View v, MotionEvent e){
bool handled = false;
if(flingDetector != null){
handled = flingDetector.OnTouchEvent(e);
}
if(v.GetType() == typeof(Spinner)){
return !handled;
}else{
return handled;
}
}
非常感谢任何帮助。