2016-08-01 75 views
0

如何將GestureOverlayView放在我的CoordinatorLayout中NestedScrollView? ,因爲我的問題是,如果我畫在gestureOverlay滾動偶頁,手勢是不可用的。CoordinatorLayout中的GestureOverlayView滾動和NestedScrollView

activity.xml

<android.support.design.widget.CoordinatorLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    android:id="@+id/scrollViewreceipt" 
    tools:context=".activities.activity"> 

    <android.support.v4.widget.NestedScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:orientation="vertical" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 

      <android.support.v7.widget.RecyclerView 
       android:id="@+id/activityRecicler" 
       android:layout_width="match_parent" 
       android:layout_height="300dp" 
       android:layout_marginTop="15dp" 
       app:stackFromEnd="true" /> 
      <android.gesture.GestureOverlayView 
       android:id="@+id/signaturePad" 
       android:layout_width="match_parent" 
       android:layout_height="80dp" 
       android:layout_weight="5" 
       android:background="#d3d3d3" 
       android:eventsInterceptionEnabled="true" 
       android:fadeEnabled="false" 
       android:gestureColor="#333" 
       android:gestureStrokeLengthThreshold="0.1" 
       android:gestureStrokeType="multiple" 
       android:fadeOffset="5000" 
       android:orientation="vertical"> 
      </android.gesture.GestureOverlayView> 
      <Button android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:onClick="testImage" 
       android:text="testami" 
      /> 
     </LinearLayout> 
     </android.support.v4.widget.NestedScrollView> 
     <android.support.design.widget.FloatingActionButton 
      android:id="@+id/fab" 
      android:layout_width="56dp" 
      android:layout_height="56dp" 
      android:layout_gravity="bottom|end" 
      android:layout_margin="@dimen/fab_margin" 
      app:backgroundTint="#b2d33f" 
      android:src="@drawable/ic_save_black_36dp" 
      android:onClick="saveReceipt" /> 
</android.support.design.widget.CoordinatorLayout> 

如果我在垂直繪製GestureOverlayView整個頁面滾動和停止平局。

回答

0

我已經解決了與擴展NestedScrollView類:

public class CustomView extends android.support.v4.widget.NestedScrollView { 
    private boolean enableScrolling = true; 

    public boolean isEnableScrolling() { 
     return enableScrolling; 
    } 

    public void setEnableScrolling(boolean enableScrolling) { 
     this.enableScrolling = enableScrolling; 
    } 

    public CustomScrollView(Context context, AttributeSet attrs, int defStyle) { 
     super(context, attrs, defStyle); 
    } 

    public CustomScrollView(Context context, AttributeSet attrs) { 
     super(context, attrs); 
    } 

    public CustomScrollView(Context context) { 
     super(context); 
    } 

    @Override 
    public boolean onInterceptTouchEvent(MotionEvent ev) { 
     Log.e("enabled", String.valueOf(isEnableScrolling())); 
     if (isEnableScrolling()) { 
      return super.onInterceptTouchEvent(ev); 
     } else { 
      return false; 
     } 
    } 
    @Override 
    public boolean onTouchEvent(MotionEvent ev) { 
     if (isEnableScrolling()) { 
      return super.onTouchEvent(ev); 
     } else { 
      return false; 
     } 
    } 
} 

以及活動實現GestureOverlayView.OnGestureListener

@Override 
public void onGestureStarted(GestureOverlayView overlay, MotionEvent event) { 
    myScrollView.setEnableScrolling(false); 
} 

@Override 
public void onGesture(GestureOverlayView overlay, MotionEvent event) { 
} 

@Override 
public void onGestureEnded(GestureOverlayView overlay, MotionEvent event) { 
    myScrollView.setEnableScrolling(true); 
} 

而在我的XML我改變android.support.v4.widget.NestedScrollViewCustomView

相關問題