Prevent ImageView from receiving touch events when scrolling

ぐ巨炮叔叔 提交于 2019-12-11 22:12:15

问题


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.

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


Some of the codes

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

Notes:

  • 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

回答1:


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.



来源:https://stackoverflow.com/questions/24152846/prevent-imageview-from-receiving-touch-events-when-scrolling

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!