长按,然后在Android应用中的不同控件上滑动

时间:2015-03-27 18:46:01

标签: android xamarin swipe imagebutton seekbar

我有一个图像按钮,点击一下,长按一下就可以了。在长按时我会显示一个自定义垂直搜索栏。除了一个要求之外,我需要的所有功能都是完全可用的。我需要能够在长按按钮而不抬起手指的情况下开始向上滑动手势。滑动手势应该在我的垂直搜索栏上运行。我已经可以做到这一点但是长按按钮后我需要抬起手指。这是我到目前为止所拥有的

public class MainActivity : Activity
{
    private ImageButton m_jump1;
    private VerticalSeekBar m_seekUp;
    private TextView m_progress;
    private string[] m_values;

    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        // Set our view from the "main" layout resource
        SetContentView(Resource.Layout.Main);
        m_values = new[] { "-5 Sec", "-15 Sec", "-1 Min", "-5 Min", "-15 Min", "-30 Min", "-1 H", "-6 H" };

        m_seekUp = FindViewById<VerticalSeekBar>(Resource.Id.SliderUp);
        m_seekUp.ProgressChanged += OnProgressChanged;
        m_seekUp.Touch += OnTouch;
        m_jump1 = FindViewById<ImageButton>(Resource.Id.Jump1);
        m_jump1.Click += OnJump;
        m_jump1.LongClick += OnShowSliderUp;
        m_progress = FindViewById<TextView>(Resource.Id.ProgressTextView);
        m_progress.Text = m_values[m_seekUp.Progress];
    }

    public override bool OnTouchEvent(MotionEvent e)
    {
        if (e.Action == MotionEventActions.Down)
        {
            if (m_seekUp.Visibility == ViewStates.Visible)
            {
                var rect = new Rect(m_seekUp.Left, m_seekUp.Top, m_seekUp.Right, m_seekUp.Bottom);
                if (!rect.Contains((int)e.RawX, (int)e.RawY))
                {
                    m_seekUp.Progress = 1;
                    m_seekUp.Visibility = ViewStates.Invisible;
                    m_progress.Visibility = ViewStates.Invisible;
                }
            }
        }
        return base.OnTouchEvent(e);
    }

    private void OnJump(object sender, EventArgs args)
    {
        if (m_seekUp.Visibility == ViewStates.Visible)
        {
            m_seekUp.Visibility = ViewStates.Invisible;
            m_progress.Visibility = ViewStates.Invisible;
        }
    }

    private void OnShowSliderUp(object sender, EventArgs args)
    {
        if (m_seekUp.Visibility == ViewStates.Invisible)
        {
            m_seekUp.Visibility = ViewStates.Visible;
            m_progress.Visibility = ViewStates.Visible;
        }
    }

    private void OnTouch(object sender, View.TouchEventArgs e)
    {
        switch (e.Event.Action)
        {
            case MotionEventActions.Up:
                m_seekUp.Progress = 1;
                m_seekUp.Visibility = ViewStates.Invisible;
                m_progress.Visibility = ViewStates.Invisible;
                break;
            case MotionEventActions.Move:
                e.Handled = false;
                break;
            case MotionEventActions.Down:
                e.Handled = false;
                break;
        }
    }

    private void OnProgressChanged(object sender, SeekBar.ProgressChangedEventArgs e)
    {
        switch (e.Progress)
        {
            case 0:
                m_progress.Text = m_values[e.Progress];
                break;
            case 1:
                m_progress.Text = m_values[e.Progress];
                break;
            case 2:
                m_progress.Text = m_values[e.Progress];
                break;
            case 3:
                m_progress.Text = m_values[e.Progress];
                break;
            case 4:
                m_progress.Text = m_values[e.Progress];
                break;
            case 5:
                m_progress.Text = m_values[e.Progress];
                break;
            case 6:
                m_progress.Text = m_values[e.Progress];
                break;
            case 7:
                m_progress.Text = m_values[e.Progress];
                break;
        }
    }

}

我正在使用Xamarin但是Java中的任何答案都会起作用,我将自己转换代码

0 个答案:

没有答案