Webview in Scrollview

后端 未结 6 872
南旧
南旧 2020-11-29 02:40

I have to place WebView into ScrollView. But I have to put some views into the same scrollview before webview. So it looks like this:



        
6条回答
  •  [愿得一人]
    2020-11-29 03:31

    Thanks for your question, @Dmitriy! And also thanks a lot to @sven for the answer.

    But I hope there is a workaround for the cases where we need to put WebView inside the ScrollView. As sven correctly noticed the main issue is that scroll view intercepts all the touch events that can be used for the vertical scrolling. So workaround is obvious - extend scroll view and override ViewGroup.onInterceptTouchEvent(MotionEvent e) method in such a way the scroll view become tolerant to it's child views:

    1. process all touch events that can be used for vertical scrolling.
    2. dispatch all of them to the child views.
    3. intercept events with vertical scrolling only (dx = 0, dy > 0)

    Ofcourse this solution can only be used in couple with appropriate layout. I have made sample layout that can illustrate the main idea.

        
    
        
    
            
    
                
    
                
    
                
    
                
    
               
    
            
        
    
    

    So that the main idea itself is to avoid vertical scrolling conflicts by putting all the views (header, webview, footer) inside vertical linear layout, and correctly dispatch touch events in order to allow horizontal and diagonal scrolling. I'm not sure whether it could be useful, but I have created the sample project with TolerantScrollView and layout sample, you can download it here.

    What's more - I have viewed the solution with accessing to the closed API via reflections and I guess it is rather hucky. It is also don't work for me because of gray rectangle artifacts over the webview on some HTC devices with Android ICS. Maybe someone knows what is the problem and how we can solve it?

提交回复
热议问题