2014-09-22 1 views
1

내 XML이 있습니다왜 스크롤 뷰 내부에서 스 와이프를 감지 할 수 없습니까?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    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" > 

    <ImageView 
     android:id="@+id/jokeIcon" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" 
     android:contentDescription="@string/app_name" 
     /> 

    <ScrollView 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_below="@+id/jokeIcon" > 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" > 

      <TextView 
       android:id="@+id/allJokesTxt" 
       style="?android:textAppearanceMedium" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:gravity="center" 
       android:lineSpacingMultiplier="1.2" 
       android:padding="16dp" /> 

     </LinearLayout> 
    </ScrollView> 

</RelativeLayout> 

내 활동이 코드 :

public boolean onTouchEvent(MotionEvent event) { 

     switch (event.getAction()) { 
      case MotionEvent.ACTION_DOWN: 
       x1 = event.getX(); 
       break; 
      case MotionEvent.ACTION_UP: 
       x2 = event.getX(); 
       float deltaX = x2 - x1; 

       if (Math.abs(deltaX) > MIN_DISTANCE) { 
        changeText(); 

       } else { 
        // consider as something else - a screen tap for example 
       } 
       break; 
     } 
     return super.onTouchEvent(event); 
    } 


private void changeText(){ 
    // Left to Right swipe action 
    if (x2 > x1) { 
     if (jokesCounter > 0) { 
      --jokesCounter; 
      currentJoke.setVisibility(View.VISIBLE); 
      currentJoke.setText(jokesCollector.get(jokesCounter)); 
     } else { 
      Context context = getApplicationContext(); 
      CharSequence text = "xxx"; 
      int duration = Toast.LENGTH_SHORT; 

      Toast toast = Toast.makeText(context, text, duration); 
      toast.show(); 
     } 

    } 

    // Right to left swipe action 
    else { 
     if (jokesLengthCounter >= jokesCounter) { 
      ++jokesCounter; 

      currentJoke.setVisibility(View.VISIBLE); 
      currentJoke.setText(jokesCollector.get(jokesCounter)); 
     } else { 
      Context context = getApplicationContext(); 
      CharSequence text = "xxx"; 
      int duration = Toast.LENGTH_SHORT; 

      Toast toast = Toast.makeText(context, text, duration); 
      toast.show(); 
     } 

    } 

}

지금이 변화를 화면에 텍스트를 가정한다 때 사용자의 와이프를 왼쪽에서 오른쪽으로, 또는 오징어로. 문제는 스 와이프가 ìmageView에서 완료되었을 때만 감지된다는 것입니다. 실제로는 ScrollView (실제 textView에서) 스 와이프가 전혀 감지되지 않습니다.

왜 일어나고 있는지? 나는 내가 여기있는 극단적 인 부분을 놓치고 있지만, 나는 그 순간을 발견 할 수 없다는 것을 안다. 너 나 한테 밀어 줄 수있어?

답변

관련 문제