2013-12-23 88 views
2

我有一些視圖層次父視圖不趕滾動手勢

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/TOP_VIEW_LAYOUT" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <LinearLayout 
     android:layout_width="0px" 
     android:layout_height="0px" 
     android:focusable="true" 
     android:focusableInTouchMode="true" > 
    </LinearLayout> 

    <BASearchView 
     android:id="@+id/SEARCH_FIELD" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content">  
    </BASearchView> 

    <BalanceView 
     android:id="@+id/CARD_INFO_FIELD" 
     android:layout_width="match_parent" 
     android:layout_height="44dp"/> 
</LinearLayout> 

其中public class BASearchView extends LinearLayoutpublic class BalanceView extends RelativeLayout。我也有public class TopView extends LinearLayout其中使用TOP_VIEW_LAYOUT ..所以,時間的問題。我試圖調度用戶事件TopView

@Override 
public boolean dispatchTouchEvent(MotionEvent event) { 
    Log.i(TAG, "dispatchTouchEvent() has been called"); 
    mGestureDetector.onTouchEvent(event); 
    return super.dispatchTouchEvent(event); 
} 

其中mGestureDetector是SimpleGestureDetector

private SimpleOnGestureListener mGestureListener = new SimpleOnGestureListener() { 
    @Override 
    public boolean onFling(MotionEvent e1, MotionEvent e2, float vx, float vy){ 
     Log.i(TAG, "TopView fling has been detected"); 
     return false; 
    } 
     public boolean onScroll (MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { 
      Log.i(TAG, "TopView scroll has been detected"); 
      return false; 
     } 
    }; 

的對象,我有一個問題.. onScroll(根據手勢檢測器)被稱爲只有當啓動內點BASearchView,不在BalanceView ..爲什麼?? !!我不明白:(

回答

0

嗯.. 我找到了一個醜陋的解決方案.. 簡單的我加空onClickListenerBalanceView,它已經成爲工作

public class BalanceView extends RelativeLayout { 

     public BalanceView(Context context, AttributeSet attrs, int defStyle) { 
      super(context, attrs, defStyle); 
      init(); 
     } 
     private void init() { 
      LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      inflater.inflate(R.layout.balance_view, this, true); 

      setOnClickListener(new OnClickListener() { 
       @Override 
       public void onClick(View v) {     
       }   
      }); 
      //some code.. 
     } 

     //some class code... 
} 

任何人都可以解釋, ?)

相關問題