我有这个布局,如果我不在 Horizo​​ntalScrollView 中使用 fillviewport=true ,它的缩放会很奇怪(可能是由于不明智的布局嵌套)。

当 fillviewport=false 时,一切都工作正常(除了奇怪的缩放),但是当 fillviewport=true 时,缩放是完美的,但不会发生滚动。

这是布局(注:我知道你不应该将网络视图放在滚动视图中。但是 webview 没有 smoothscrollto 也没有公开 setscroller 方法,所以......哎呀。)

<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/webContainer"
    android:layout_below="@+id/titlebar"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true">
    <WebView 
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/webZ"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
    />
</HorizontalScrollView>

设置 android:fillViewport="true" 通常不会禁用视图中的滚动,不是吗?

只是应该确保滚动视图填充视口,无论其内容的大小如何,是吗?我认为视口是屏幕的可见区域,并且 web 视图中可见区域边缘肯定有更多内容,我只是无法再滚动到它。

我可以从 logcat 中看到滚动方法正在被调用,它们只是不改变屏幕。(除非我将 fillviewport 设置为 false。)

有帮助吗?

解决方案

问题是您使用“ Fill_parent”,这意味着“和我的父母一样大”。改用wrap_content进行宽度。

其他提示

我在包含 WebView 的标准 ScrollView 中遇到了类似的问题:滚动不再起作用了。将 fill_parent 更改为 wrap_content 对我来说不起作用。

当扩展视图是 TextView 时,Romain Guy 的示例工作正常,但当它被 WebView 替换时则不然。

什么不起作用:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:fillViewport="true">
    <LinearLayout
        android:layout_width="fill_parent" android:layout_height="wrap_content"
        android:orientation="vertical">
        <WebView android:id="@+id/webview"
            android:layout_width="fill_parent" android:layout_height="wrap_content"
            android:layout_weight="1.0">
        </WebView>
        <Button 
            android:layout_width="fill_parent" android:layout_height="wrap_content"
            android:text="Click">
        </Button>
    </LinearLayout>     
</ScrollView>

当我在网络视图中添加少量数据时,似乎没问题:

small_data_not_ok1

但是当我用大量数据填充 WebView 时,它不起作用,如下所示:

small_data_not_ok2

该按钮始终显示并且滚动不再起作用。事实上,触摸滚动不起作用,而 DPAD 滚动起作用......

我没有找到任何原因,但我找到了解决方法:它包括添加一个包含 WebView 的 LinearLayout

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:fillViewport="true">
    <LinearLayout
        android:layout_width="fill_parent" android:layout_height="wrap_content"
        android:orientation="vertical">
        <LinearLayout android:id="@+id/linearlayout"
            android:layout_width="fill_parent" android:layout_height="wrap_content"
            android:layout_weight="1.0"
            android:orientation="vertical">
            <WebView android:id="@+id/webview"
                android:layout_width="fill_parent" android:layout_height="wrap_content">
            </WebView>
        </LinearLayout>
        <Button 
            android:layout_width="fill_parent" android:layout_height="wrap_content"
            android:text="Click">
        </Button>
    </LinearLayout>     
</ScrollView>

现在它工作正常:

ok1 ok2

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top