Android comment ajouter Geste de balayage sur LinearLayout sans onDown vrai

Je suis en train de travailler sur le Geste de l'activité dans android, j'ai utilisé de la classe afin de détecter l'action de balayage est

public class ActivitySwipeDetector  implements View.OnTouchListener {
static final String logTag = "ActivitySwipeDetector";
private Activity activity;
static final int MIN_DISTANCE = 100;
private float downX, downY, upX, upY;
public ActivitySwipeDetector(Activity activity){
this.activity = activity;
}
public void onRightToLeftSwipe(){
Log.i(logTag, "RightToLeftSwipe!");
Toast.makeText(activity, "RightToLeftSwipe", Toast.LENGTH_SHORT).show();
//activity.doSomething();
}
public void onLeftToRightSwipe(){
Log.i(logTag, "LeftToRightSwipe!");
Toast.makeText(activity, "LeftToRightSwipe", Toast.LENGTH_SHORT).show();
//activity.doSomething();
}
public void onTopToBottomSwipe(){
Log.i(logTag, "onTopToBottomSwipe!");
//Toast.makeText(activity, "onTopToBottomSwipe", Toast.LENGTH_SHORT).show();
//activity.doSomething();
}
public void onBottomToTopSwipe(){
Log.i(logTag, "onBottomToTopSwipe!");
//Toast.makeText(activity, "onBottomToTopSwipe", Toast.LENGTH_SHORT).show();
//activity.doSomething();
}
public boolean onTouch(View v, MotionEvent event) {
switch(event.getAction()){
case MotionEvent.ACTION_DOWN: {
downX = event.getX();
downY = event.getY();
return true;
}
case MotionEvent.ACTION_UP: {
upX = event.getX();
upY = event.getY();
float deltaX = downX - upX;
float deltaY = downY - upY;
//swipe horizontal?
if(Math.abs(deltaX) > MIN_DISTANCE){
//left or right
if(deltaX < 0) { this.onLeftToRightSwipe(); return true; }
if(deltaX > 0) { this.onRightToLeftSwipe(); return true; }
}
else {
Log.i(logTag, "Swipe was only " + Math.abs(deltaX) + " long, need at least " + MIN_DISTANCE);
return false; //We don't consume the event
}
//swipe vertical?
if(Math.abs(deltaY) > MIN_DISTANCE){
//top or down
if(deltaY < 0) { this.onTopToBottomSwipe(); return true; }
if(deltaY > 0) { this.onBottomToTopSwipe(); return true; }
}
else {
Log.i(logTag, "Swipe was only " + Math.abs(deltaX) + " long, need at least " + MIN_DISTANCE);
return false; //We don't consume the event
}
return true;
}
}
return false;
}
}

mon fichier xml est

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/action_settings"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
</LinearLayout>

Et dans Mon activité je l'appel comme ça

ActivitySwipeDetector activitySwipeDetector = new ActivitySwipeDetector(this);
LinearLayout lowestLayout = (LinearLayout)this.findViewById(R.id.action_settings);
lowestLayout.setOnTouchListener(activitySwipeDetector);

J'ai appelé ActivitySwipeDetector(this); si Sa fonctionne bien avec la pleine activité. Mais comment puis-je faire Glisser le détecteur seulement à LinearLayout pas à l'Ensemble de l'Activité. Merci de m'aider.

  • Vous êtes à la fixation de la touche d'un écouteur pour un point de vue particulier. Décider de ce point de vue, vous voulez détecter le passage des doigts sur et fixez-la à la bonne vue. Si vous le fixez au niveau le plus haut dans la vue de l'activité comme vous l'avez fait ici, il va travailler sur l'ensemble de l'activité.
  • Mais si j'attache enfant de voir sa fonctionne pas...