需要在Web视图android中仅禁用垂直滚动

时间:2018-03-23 13:43:39

标签: android webview vertical-scrolling

在XML中,我将 android:scrollbars =“none”添加到网页视图

<WebView
    android:id="@+id/wvProgress"
    android:layout_width="match_parent"
    android:scrollbars="none"
    android:layout_height="match_parent" />

在java文件中,

wvProgress.setVerticalScrollBarEnabled(false);

但是,仍然没有禁用某些垂直滚动条,并且在Web视图下方会显示一些额外的空白区域。 Show screenshot

1 个答案:

答案 0 :(得分:0)

尝试了多种方法之后,终于找到了我的问题的解决方案 - 只显示水平滚动并删除webview中的垂直滚动。

首先,我需要设置webview的高度和宽度。然后将webview放在水平滚动视图中。所以,我发现垂直滚动被删除,只有水平滚动可用。 为了获得更好的UI性能和滚动,我将水平滚动视图放在framelayout中。

我的源代码如下所示: -

 <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <HorizontalScrollView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scrollbars="none">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                    <WebView
                        android:id="@+id/wvProgress"
                        android:minHeight="0dp"
                        android:layout_width="@dimen/_800dp"
                        android:layout_height="@dimen/_300dp" />
                </LinearLayout>
            </HorizontalScrollView>

        </FrameLayout>