2013-01-16 16 views
7

ここに解決策があります。私のmain.xmlにXML TimePickerとScrollViewがあり、設定でTimePickerがスクロールしません。 ScrollViewを削除すると、Timepickerはうまくスクロールしますが、明らかに私は両方が必要です。ScrollViewがTimePickerのスクロールで戦っている、タイムピッカーが結果としてスクロールしていない

タッチイベントを取得するために両者が戦っているようですが、問題を引き起こしているようです。私は無関係なコードを削除しますが、レイアウトがレイアウトされているかだけをお見せするためにアウトラインを守ってきた

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

は、ここに私のコードです。

XMLに修正がありますか?私はandroid:fillViewPort=""のようなものを試しましたが、それは何もしていません。私のTimePickerはDialogか何かの一部ではなく、うまくいけばそれをそのまま保つことができます。

答えて

12

は、タッチイベントを上書きするカスタムTimePickerクラスを作成し、これを呼び出して、解決策を見つけた:

@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

は、これが私の一日保存しました! –

関連する問題