2013-06-27 38 views
1

我使用第三方組件(AndroidSideMenu),它允許將整個活動向右拖動以顯示側面菜單。可拖動視圖中的SeekBar(SlideHolder)

在佈局的主要(非菜單)部分,我有一個水平的SeekBar。 問題是,當我開始拖動SeekBar按鈕時,整個佈局隨之拖動,因爲SlideHolder組件也響應拖動事件。

我不確定在Android中如何管理觸摸事件,但有沒有辦法在SeekBar處理這些事件後停止這些事件,以便它們不會到達父容器? 因此,當您拖動Seekbar時,整個屏幕(父級)必須保持放置,但是當您拖出SeekBar時,它必須仍然按照側面菜單的要求工作?

感謝

回答

1

在搜索欄的容器,創建和應用(於搜索條)像OnTouchListener如下:

private final OnTouchListener onTouchListener = new OnTouchListener() 
{ 
    public boolean onTouch(View v, MotionEvent event) 
    { 
     // If the View in question isn't a child of the seekBar and 
     // isn't the seekBar itself, then return and don't consume the event. 
     if ((seekBar.findViewById(v.getId()) == null) && 
      (v.getId() != seekBar.getId())) 
     { 
      return false; 
     } 

     // The View is either a child of the seekBar or is the seekBar itself, 
     // so we pass the event along to the seekBar and return true, signifying 
     // that the event has been consumed. 
     seekBar.onTouchEvent(event); 

     return true; 
    } 
} 

試試這個,看看它是否工作;您可能需要爲if語句創建更健壯的條件。