2013-08-23 84 views
14

我想用搜索條在抽屜式導航搜索欄在NavigationDrawer

基本上我需要左右滑動來設定搜索條的,那麼,你猜對了,它滑動導航抽屜...

我想要做的是滑動搜索欄時,它的重點和導航drawer時,它不是。

我該怎麼做?

這裏是我的代碼中設置的項目(我沒有設置搜索條還)

private View onCritereView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 

    View mView = inflater.inflate(R.layout.fragment_critere, container, false); 
    LinearLayout mLinearLayout = (LinearLayout) mView.findViewById(R.id.critere_linearlayout); 

    View mViewElement = inflater.inflate(R.layout.item_critere, null); 
    ((TextView)mViewElement.findViewById(R.id.critere_title)).setText("Prix Maximum"); 

    mLinearLayout.addView(mViewElement); 

    return mView; 
} 

這裏是item_critere.xml與搜索條時:

<?xml version="1.0" encoding="utf-8"?> 
<TableLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/critere_item" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:stretchColumns="*"> 

    <TableRow 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent"> 

     <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textAppearance="?android:attr/textAppearanceMedium" 
       android:text="Large Text" 
       android:id="@+id/critere_title" 
       android:layout_gravity="left|center_vertical" 
       android:layout_column="0"/> 

     <SeekBar 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:id="@+id/critere_qualifier" 
       android:layout_column="1" 
       android:layout_span="4"/> 
    </TableRow> 

    <TableRow 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent"> 

     <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textAppearance="?android:attr/textAppearanceSmall" 
       android:text="Medium Text" 
       android:id="@+id/critere_value" 
       android:layout_span="4"/> 
    </TableRow> 

</TableLayout> 

感謝提前:)

回答

28

只需添加一個onTouchListener。當您觸摸seekbar上的屏幕(action_down)時,不允許父母攔截該事件。

seekbar.setOnTouchListener(new ListView.OnTouchListener() 
{ 
    @Override 
    public boolean onTouch(View v, MotionEvent event) 
    { 
     int action = event.getAction(); 
     switch (action) 
     { 
     case MotionEvent.ACTION_DOWN: 
      // Disallow Drawer to intercept touch events. 
      v.getParent().requestDisallowInterceptTouchEvent(true); 
      break; 

     case MotionEvent.ACTION_UP: 
      // Allow Drawer to intercept touch events. 
      v.getParent().requestDisallowInterceptTouchEvent(false); 
      break; 
     } 

     // Handle seekbar touch events. 
     v.onTouchEvent(event); 
     return true; 
    } 
}); 
+0

哇,它工作得很好!謝謝:) – nsvir

+0

這實際上是爲了在ScrollView中使用ListView而複製的。所以它是新的SeekBar.OnTouchListener而不是ListView.onTouchListener。 這是一個非常簡單的方法,它適用於很多種類的問題 – dumazy

+0

現在好了。x)我在導航抽屜和seekbar之間添加了滾動視圖。我只想禁用導航抽屜的interceptTouch事件而不是scrollview x)這可能嗎? – nsvir