android - 在 ScrollView 中滚动 Webview

标签 android webview scrollview

我有什么:
现在我有一个 ScrollView 作为 parent 。在这个 ScrollView 中,我使用了一个加载 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>    

我想要的:
我想在其中滚动 webView。当我触摸 webView 时,不幸的是调用了父 ScrollView 。 我还必须保留父 ScrollView ,但除此之外,当我触摸 webView 时,我想在其中滚动 WebView 内容。

我该怎么做?

最佳答案

创建自定义触摸拦截 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);
    }          
}

layout.xml

<com.package.custom.widgets.CustomWebview
                android:id="@+id/view_extra"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                 />

关于android - 在 ScrollView 中滚动 Webview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12567472/

相关文章:

Android - 在哪里放置应用程序的一般信息/印记/联系信息/关于?

javascript - Android 4.2.1、WebView 和 javascript 界面中断

android - 如果 ScrollView 仅支持一个直接子级,我应该如何使整个布局可滚动?

c# - WPF ScrollViewer 端

ios - 在 UITableView 滚动时更新 MKMapView,从单元格获取坐标

android - Titanium SDK 在 Ubuntu 12.04 上无法识别 Titanium CLI、node、alloy 或 npm

android - 飞行模式的 Settings.system.putInt() 不工作

objective-c - WebView打开 '_blank'链接

android - Android WebView 上的输入文件

Android:如何删除工具栏和状态栏之间的线