ScrollView and Gallery interfering

前端 未结 5 1166
我在风中等你
我在风中等你 2020-12-16 06:44

I have a Gallery composed of many ScrollViews each of which occupies the whole screen. problem is the ScrollViews\' onTouchEvent returns true and therefore prevent any other

5条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-16 07:28

    I found the Gallery scrolling-behaviour of atraudes' solution less than optimal so I looked for an other solution. Finally I found one which works perfectly for me:

    1. Create a class FriendlyGallery by extending Gallery and overwrite onTouchEvent, onInterceptTouchEvent, onScroll and onFling. Use the onInterceptTouchEvent to "register" the the currently displayed ScrollView with the FriendlyGallery and the "remote control" this ScrollView (using it scrollBy and fling Methods) within onScroll and onFling of FriendlyGallery (velocityY of onFling = -1*velocityY of fling !!!). Return true for onTouchEvent to capture the Touch Events here!
    2. Create a class FriendlyScrollView by extending ScrollView and overwrite onTouchEvent, onInterceptTouchEvent just returning "false" in order to keep the Touch Events from interfering with your "remote controlling" the ScrollView.

提交回复
热议问题