2012-01-10 55 views
0

昨天我在StackOverflow中提出了一个问题,但无法得到答案。 我附上相同的Question link寻找答案的网址。 我正在使用WebView呈现页面,并且无法使用保存在资产文件夹中的html进行上下滚动。 完美运行在模拟器,但设备我不能滚动。在android中使用HTML页面上下滚动

期待您的回复。 谢谢。

回答

1

使用,这是在java的

try { 
     InputStream is = getAssets().open("help.html"); 

     // We guarantee that the available method returns the total 
     // size of the asset... of course, this does mean that a single 
     // asset can't be more than 2 gigs. 
     int size = is.available(); 

     // Read the entire asset into a local byte buffer. 
     byte[] buffer = new byte[size]; 
     is.read(buffer); 
     is.close(); 

     // Convert the buffer into a Java string. 
     String text = new String(buffer); 

     final String mimeType = "text/html"; 
     final String encoding = "utf-8"; 

     // Finally stick the string into the text view. 
     WebView wv = (WebView)findViewById(R.id.help); 
     wv.loadData(text, mimeType, encoding); 
    } catch (IOException e) { 
     // Should never happen! 
     throw new RuntimeException(e); 
    } 
+0

你的代码是不是在设备上工作的尝试代码

代码,XML

<ScrollView android:scrollbars="vertical" android:layout_height="wrap_content" android:layout_width="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"> <LinearLayout android:layout_height="fill_parent" android:layout_width="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical"> <WebView android:layout_height="wrap_content" android:layout_width="fill_parent" android:id="@+id/help"/> <ImageButton android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/close" android:background="@drawable/ok_button" android:layout_centerHorizontal="true" android:layout_gravity="center" android:layout_alignParentBottom="true"/> </LinearLayout> </ScrollView> 

代码。 – Mukunda 2012-01-10 11:36:58

+0

雷迪P感谢绝对完美的答案。我在ScrollView中丢失了LinearLayout,因此我将ScrollView的根布局移除了,并使用了LinearLayout,并且工作正常。但是如果根布局是ScrollView,则滚动WebView不起作用,即任何WebView滚动如果在ScrollView下都不起作用。 – Mukunda 2012-01-12 10:02:23