触摸android.gesture.GestureOverlayView时阻止ScrollView中的滚动

时间:2016-07-27 09:33:18

标签: android android-layout android-gesture

我尝试在ScrollView中实现android.gesture.GestureOverlayView。 在我的 activity.xml

<?xml version="1.0" encoding="utf-8"?>
   <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:id="@+id/scrollViewreceipt"
   >
   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="vertical" android:layout_width="match_parent"
   android:layout_height="match_parent">
       <include
       android:id="@+id/include1"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       layout="@layout/toolbar" />
      <Spinner
        android:id="@+id/custom_spinner"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:theme="@android:style/Theme.Holo.Light.DarkActionBar"/>

      <ListView
        android:id="@+id/customList"
        android:layout_width="match_parent"
        android:layout_height="300dp"
        android:layout_marginTop="15dp" />

      <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="test"/>
</LinearLayout>

但是当我尝试在我的android.gesture.GestureOverlay上绘制视图滚动时它是可以使用的,所以我问如何在触摸android.gesture.GestureOverlayView时阻止滚动。

1 个答案:

答案 0 :(得分:1)

我这样解决了:

我使用 CustomScrollView

扩展了ScrollView
$(document).ready(function() {
    //var fromDate = $('#fromdatepicker').datepicker();
    var toDate = $('#datepicker').datepicker(

    ).on('change', function(e) {
        console.log(e);
    });
    // here i need current date and do some calculation and then set again.
    console.log(toDate);
});

在我的XML中,我使用带有id

的新扩展类更改了ScrollView
public class CustomScrollView extends ScrollView {
 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) {

    if (isEnableScrolling()) {
        return super.onInterceptTouchEvent(ev);
    } else {
        return false;
    }
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
    if (isEnableScrolling()) {
        return super.onTouchEvent(ev);
    } else {
        return false;
    }
}
}

在我的 ActivityClass

<com.itmind.spac.spacapp.custom_extends.CustomScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/scrollViewreceipt"
>......</com.itmind.spac.spacapp.custom_extends.CustomScrollView>