防止ImageView在滚动时接收触摸事件

防止ImageView在滚动时接收触摸事件

本文介绍了防止ImageView在滚动时接收触摸事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个很多 ImageView 的应用程序,我需要在其中一些附加一个触摸监听器。在这样做的时候,我遇到了一个问题。如果指针被按住在附有触摸监听器的 ImageView 的位置,并且即将产生滚动事件,则查看 s和w $ c中的 ScrollView ,其中事件实际发生,事件应该属于w / c。 屏幕以快速的速度滚动,然后返回第一个指针被触摸的地方,因此这意味着它是一种不必要的行为。

I'm making an app with lots of ImageViews and I needed to attach a touch listener in some of them. While doing this, I encountered a problem. If the pointer was held down at the location where the ImageView with touch listeners attached to it and was about to produce a scrolling event, there seems a fighting scene between the Views and the ScrollView in w/c where the event was actually occured and in w/c the event is supposed to belong. The screen scrolls in a fast rate then return where the first pointer was touched down, so it means it is an unwanted behavior.

设置 onTouchListener ImageView 中使滚动不安和不需要,如何防止 ImageView 在滚动时接收到触摸事件?

Setting an onTouchListener in the ImageView makes the scrolling uneasy and unwanted, how do I prevent ImageView from receiving touch events when scrolling?

布局 act_map_view.xml

<?xml version="1.0" encoding="utf-8"?>

<com.nkraft.mobiletomblocator.CustomVScroll
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/vScroll"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scrollbars="none" >

    <com.nkraft.mobiletomblocator.CustomHScroll
        android:id="@+id/hScroll"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scrollbars="none" >

            <com.nkraft.mobiletomblocator.CustomGridLayout
                android:id="@+id/map_grid"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >

            </com.nkraft.mobiletomblocator.CustomGridLayout>

    </com.nkraft.mobiletomblocator.CustomHScroll>

</com.nkraft.mobiletomblocator.CustomVScroll>

注意:


  • 在运行时, GridLayout 填入 ImageView

  • 我定制了我的水平和垂直 ScrollView ,以便我可以同时在两个方向滚动,即对齐滚动

  • The GridLayout is populated with ImageViews at runtime.
  • I customized my horizontal and vertical ScrollView so that I can scroll in both directions concurrently i.e diagonal scrolling

推荐答案

从我提到的笔记中,我想到了我目前面临的问题的线索。我认为这个问题在标准android的滚动条被实现之前就已经被考虑过了。我发生的主要原因是我扩展了滚动条的类,并完全替代了它的默认行为。所以为了实现我想要的(带滚动条的滚动条)我遵循这个,并用这个 TwoDScrollView 替换我的垂直和水平scrollview,同样感谢指示我。

From the notes I've mention, I figured a clue from the problem I'm currently facing. I think this issue had been thought before the standard android's scrollbar was implemented. The main reason this occurs to me is that I extended the class of the scrollbars and totally replacing the default behavior of it. So for me to achieve what I want (the scrollbar with diagonal scrolling) I follow this post and replace both my vertical and horizontal scrollview with this TwoDScrollView, also thanks for this post directing me to it.

这篇关于防止ImageView在滚动时接收触摸事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 20:33