首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >触摸ScrollView时在android.gesture.GestureOverlayView中的块滚动

触摸ScrollView时在android.gesture.GestureOverlayView中的块滚动
EN

Stack Overflow用户
提问于 2016-07-27 09:33:18
回答 1查看 637关注 0票数 0

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

代码语言:javascript
复制
<?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.GestureOverlayView上绘制视图卷轴时,它是不可用的,所以我问当我触摸android.gesture.GestureOverlayView时,如何阻止滚动。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-07-27 10:51:09

我用这种方法解决了:

我用CustomScrollView扩展了一个ScrollView

代码语言:javascript
复制
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;
    }
}
}

在XML中,我用id修改了新的扩展类ScrollView。

代码语言:javascript
复制
<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>

在我的ActivityClass

代码语言:javascript
复制
public class CustomActivity  implements GestureOverlayView.OnGestureListener {
CustomScrollView myScrollView;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState, R.layout.activity_receipts);

    GestureOverlayView signaturePad = (GestureOverlayView) findViewById(R.id.signaturePad);
    myScrollView = (CustomScrollView) findViewById(R.id.scrollViewreceipt);
    assert myScrollView != null;


    assert signaturePad != null;
    signaturePad.addOnGestureListener(this);
}
@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);
}

@Override
public void onGestureCancelled(GestureOverlayView overlay, MotionEvent event) {
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38609102

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档