6

私はこのレイアウトを持っていますが、Horizo​​ntalScrollViewでfillviewport = trueを使用しないと、(おそらく不適切なレイアウトのネストが原因で)奇妙にスケーリングされます。

fillviewport = falseの場合、すべてが桃色に機能します(奇数のスケーリングを除く)が、fillviewport = trueの場合、スケーリングは完全ですが、スクロールは発生しません。

これがレイアウトです(注:Webビューをscrollviewに配置することは想定されていません。ただし、Webviewにはsmoothscrolltoがなく、setscrollerメソッドが公開されていないため... bleh)。

<?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に設定しない限り。)

4

2 に答える 2

5

問題は、「私の親と同じくらい大きくなる」ことを意味する「fill_parent」を使用することです。代わりに、幅にwrap_contentを使用してください。

于 2011-03-15T05:32:59.277 に答える
2

WebViewを含む標準のScrollViewでも同様の問題が発生します。つまり、スクロールが機能しなくなりました。fill_parentからwrap_contentへの変更はうまくいきませんでした。

Romain Guyの例は、展開されたビューがTextViewの場合は正常に機能しますが、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>

Webビューに少量のデータを追加すると、問題ないように見えます。

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

于 2011-06-28T14:51:24.470 に答える