在Android中滚动,WebView工作正常

在Android中滚动,WebView工作正常,android,android-layout,Android,Android Layout,我有一个布局,我正在通过WebView呈现其中的HTML文档 XML布局是 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:fillViewport="true" android:scrollbars="vertical"> <

我有一个布局,我正在通过WebView呈现其中的HTML文档

XML布局是

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:scrollbars="vertical">

<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
    <LinearLayout
        android:id="@+id/header"
        android:layout_alignParentTop="true"
        android:layout_width="fill_parent" 
        android:layout_height="30dip"
        android:background="@drawable/black"
        android:tileMode="repeat">
        <ImageButton 
            android:id="@+id/btnBackHelp"
            android:src="@drawable/greenarrow"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:background="@drawable/black"
            android:tileMode="repeat"/>
      <ImageView 
          android:src="@drawable/logo"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"/>
         </LinearLayout>
         <LinearLayout 
            android:layout_height="fill_parent"
            android:layout_width="fill_parent" 
            xmlns:android="http://schemas.android.com/apk/res/android" 
            android:orientation="vertical"
            android:layout_marginTop="30dip"> 
         <WebView
            android:layout_height="fill_parent" 
            android:layout_width="fill_parent"
            android:id="@+id/helpBrowserWebview"/>
        </LinearLayout>
        <LinearLayout
        android:layout_alignParentBottom="true"
        android:layout_width="fill_parent" 
        android:layout_height="30dip"
        android:layout_weight="1"
        android:weightSum="5" 
        android:orientation="horizontal"
        android:background="@drawable/black"
        android:tileMode="repeat">

    <LinearLayout 
        android:id="@+id/footerLayoutHome"
        android:clickable="true"
        android:layout_width="fill_parent"
        android:layout_weight="1" 
        android:orientation="vertical"
        android:gravity="center" 
        android:layout_height="fill_parent">

        <ImageButton 
            android:id="@+id/footerMainBtnHome"
            android:layout_width="fill_parent" 
            android:layout_height="14dip"
            android:src="@drawable/home" 
            android:background="@drawable/black"/>
        <TextView 
            android:text="Home" 
            android:textSize="8dip"
            android:textColor="#ffffff"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </LinearLayout>
     <LinearLayout 
         android:id="@+id/footerLayoutProducts"
         android:clickable="true"
        android:layout_width="fill_parent"
        android:layout_weight="1" 
        android:orientation="vertical"
        android:gravity="center" 
        android:layout_height="fill_parent">

        <ImageButton 
            android:id="@+id/footerMainBtnProducts"
            android:layout_width="fill_parent" 
            android:layout_height="14dip"
            android:src="@drawable/products" 
            android:background="@drawable/black"/> 
            <TextView 
            android:text="Products" 
            android:textSize="8dip"
            android:textColor="#ffffff"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </LinearLayout>
     <LinearLayout 
         android:id="@+id/footerLayoutCart"
         android:clickable="true"
        android:layout_width="fill_parent"
        android:layout_weight="1" 
        android:orientation="vertical"
        android:gravity="center" 
        android:layout_height="fill_parent">

        <ImageButton 
            android:id="@+id/footerMainBtnCart"
            android:layout_width="fill_parent" 
            android:layout_height="14dip"
            android:src="@drawable/cart" 
            android:background="@drawable/black"/>
        <TextView 
            android:text="Cart" 
            android:textSize="8dip"
            android:textColor="#ffffff"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

    </LinearLayout>
     <LinearLayout 
         android:id="@+id/footerLayoutFeedback"
         android:clickable="true"
        android:layout_width="fill_parent"
        android:layout_weight="1" 
        android:orientation="vertical"
        android:gravity="center" 
        android:layout_height="fill_parent">

        <ImageButton 
            android:id="@+id/footerMainBtnFeedback"
            android:layout_width="fill_parent" 
            android:layout_height="14dip"
            android:src="@drawable/feedback" 
            android:background="@drawable/black"/>
        <TextView 
            android:text="Feedback" 
            android:textSize="8dip"
            android:textColor="#ffffff"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

    </LinearLayout>
     <LinearLayout 
         android:id="@+id/footerLayoutHelp"
         android:clickable="true"
        android:layout_width="fill_parent"
        android:layout_weight="1" 
        android:orientation="vertical"
        android:gravity="center" 
        android:layout_height="fill_parent">

        <ImageButton 
            android:id="@+id/footerMainBtnHelp"
            android:layout_width="fill_parent" 
            android:layout_height="14dip" 
            android:src="@drawable/help" 
            android:background="@drawable/black"/>
        <TextView 
            android:text="Help" 
            android:textSize="8dip"
            android:textColor="#ffffff"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

    </LinearLayout>



         </LinearLayout>
</RelativeLayout>
</ScrollView>
无论我调用什么url,我都无法滚动,甚至调用存储在资产文件夹中的html,我都无法滚动。
期待您的回复。谢谢。

我找到了这个问题更好的答案。事实证明,正如您所期望的那样,WebView确实有
scrollTo()
getScrollX()
getScrollY()
方法。它们在文档中有点隐藏,因为它们是从视图继承的(通过
AbsoluteLayout
->
ViewGroup
->View)。这显然是一种更好的方式来操作
WebView的
滚动位置,而不是有点笨重的JavaScript界面。

试试看

wv.setWebChromeClient(new WebChromeClient());
以前

wv.loadData(text, mimeType, encoding);

在试块之前也要先查找视图ID。

首先,如果你从中学到了一些东西,那么编写代码绝不是浪费时间。:-)如果您有任何疑问,请自行尝试,然后请告诉我有关您的信息,我们不必使用
scrollTo()
getScrollX()
getScrollY()
因为我刚刚更改了布局,如果WebView父级是ScrollView,则WebView的滚动不起作用。所以我使用了LinearLayout,然后在LinearLayout中调用WebView。如果有人想使用ScrollView,则将ScrollView作为父布局,在ScrollView下使用LinearLayout,在LinearLayout下使用WebView,效果非常好。我已经尝试过,但没有效果,如果在ScrollView内,则滚动WebView不起作用,但是,将ScrollView作为父布局,然后在ScrollView内部使用Linearlayout,在Linearlayout内部声明WebView,它就可以完美地工作。
wv.loadData(text, mimeType, encoding);