2013-01-16 13 views
7

Mam nadzieję, że istnieje rozwiązanie tutaj, mam XML TimePicker i ScrollView w moim main.xml i przy konfiguracji TimePicker nie przewija. Jeśli usunę ScrollView, Timepicker będzie przewijany dobrze, ale oczywiście potrzebuję obu.ScrollView walki z przewijaniem TimePicker, Timepicker nie przewijanie w wyniku

Wygląda na to, że obaj walczą o dotyku, ale powodują problemy.

Oto mój kod:

<ScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_height="match_parent" 
    android:layout_width="match_parent" 
    android:background="@color/backgroundmain"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <!-- Action Title --> 
     <ImageView /> 

     <TextView /> 

     <!-- Description --> 
     <TextView /> 

     <!-- Have to Button --> 
     <TextView /> 

     <RelativeLayout 
      android:id="@+id/TimePickerSection" 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 
      android:layout_marginTop="5dp" 
      android:layout_centerHorizontal="true" 
      android:layout_below="@id/"> 

      <TimePicker 
       android:id="@+id/TimePick" 
       android:layout_height="wrap_content" 
       android:layout_width="wrap_content" 
       android:layout_centerVertical="true" 
       android:layout_below="@id/HaveToText"/> 

      <Button 
       android:id="@+id/OkButton" 
       android:layout_height="wrap_content" 
       android:layout_width="wrap_content" 
       android:text="@string/OkText" 
       android:layout_below="@id/HaveToText" 
       android:textSize="20sp" 
       android:onClick="TimePickButton" 
       android:layout_centerVertical="true" 
       android:layout_toRightOf="@id/TimePick"/> 

     </RelativeLayout> 

    <!-- OR --> 
    <TextView /> 

    <!-- buttons --> 
    <TextView /> 

    <Button /> 

    </RelativeLayout> 

</ScrollView> 

Usunąłem kod bez znaczenia, ale trzymane zarysy tylko pokazać, jak układ jest rozplanowany.

Czy istnieje poprawka w pliku XML? Próbowałem rzeczy takie jak android:fillViewPort="", ale to nie zrobiło nic. Mój TimePicker nie jest częścią Dialogu ani nic takiego i mam nadzieję, że utrzymam to w ten sposób.

Odpowiedz

12

Znaleziono rozwiązanie, należy utworzyć niestandardową klasę timepicker a następnie zadzwonić Unieważnia dotykowych zdarzenia:

@Override 
public boolean onInterceptTouchEvent(MotionEvent ev) { 
    // Stop ScrollView from getting involved once you interact with the View 
    if (ev.getActionMasked() == MotionEvent.ACTION_DOWN) { 
     ViewParent p = getParent(); 
     if (p != null) 
      p.requestDisallowInterceptTouchEvent(true); 
    } 
    return false; 
} 
+0

ten zapisany mój dzień! –

Powiązane problemy