在滚动视图中滚动Webview

Nom*_*man 6 android scrollview webview

我有什么:
现在我有一个Scroll视图作为父母.在这个滚动视图中,我使用的是一个加载URL然后在其中显示文本的WebView.这是我的xml:

<ScrollView
    android:id="@+id/parentScroll"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/Heading" >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="5dp" >

        <WebView
            android:id="@+id/webView"
            android:layout_width="match_parent"
            android:layout_height="300dp"
            android:background="@drawable/webview" />
    </RelativeLayout>
</ScrollView>    
Run Code Online (Sandbox Code Playgroud)

我想要的是:
我想在其中滚动webView.当我触摸webView时,很遗憾地会调用父滚动视图.我还要保留父滚动视图,但除此之外,我想在我触摸webView时滚动其中的WebView内容.

我怎样才能做到这一点?

ASP*_*ASP 6

创建自定义触摸拦截Webview

CustomWebview.java

 package com.mypackage.common.custom.android.widgets

public class CustomWebview extends WebView {

    public CustomWebview(Context context) {
        super(context);
    }

    public CustomWebview(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public CustomWebview(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event){
        requestDisallowInterceptTouchEvent(true);
        return super.onTouchEvent(event);
    }          
}
Run Code Online (Sandbox Code Playgroud)

layout.xml中

<com.package.custom.widgets.CustomWebview
                android:id="@+id/view_extra"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                 />
Run Code Online (Sandbox Code Playgroud)


Cas*_*eyB 4

根据 Android 设计文档,如果滚动容器的滚动方向相同,则永远不应该将滚动容器放入滚动容器内。它不是为了处理这样的事情。

  • @CaseyB...但这是我的要求..我必须将 webView 保持在滚动视图中。你对此有什么想法吗? (2认同)
  • 那么恐怕您的要求是错误的,您永远不需要这样做。 (2认同)
  • 可以参考一下文档吗? (2认同)