2013-01-16 7 views
7

Hoffentlich eine Lösung gibt es hier, habe ich einen XML-Timepicker und Scroll in meinem main.xml und mit dem Aufbau der Timepicker bewegen sich nicht. Wenn ich die ScrollView entferne, scrollt der Timepicker gut, aber offensichtlich brauche ich beides.Scroll mit Scroll von Timepicker kämpfen, Timepicker nicht als Ergebnis Scrollen

Es scheint, als ob sie beide kämpfen, um die Berührungsereignisse zu bekommen, aber es verursacht Probleme.

Hier ist mein Code:

<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> 

ich den irrelevant Code entfernt habe, behielt aber die Umrisse nur um Ihnen zu zeigen, wie das Layout aus gelegt.

Gibt es eine Fehlerbehebung im XML? Ich habe versucht, Dinge wie android:fillViewPort="", aber das hat nichts getan. Mein TimePicker ist nicht Teil eines Dialogs oder irgendetwas und hoffentlich kann ich es so halten.

Antwort

12

die Lösung gefunden, eine benutzerdefinierte Timepicker-Klasse erstellen und dann diese Touch-Ereignisse außer Kraft zu setzen nennen:

@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

Das ist mein Tag gerettet! –