在android中使用HTML页面上下滚动
我昨天在电话里提出了一个问题,但没有得到答案。 我附上了相同的网址寻找答案。 我正在使用WebView呈现页面,无法使用保存在asset文件夹中的html上下滚动。 在emulator中运行良好,但在设备中无法滚动 期待您的回复。 谢谢。使用这是代码 xml代码在android中使用HTML页面上下滚动,android,Android,我昨天在电话里提出了一个问题,但没有得到答案。 我附上了相同的网址寻找答案。 我正在使用WebView呈现页面,无法使用保存在asset文件夹中的html上下滚动。 在emulator中运行良好,但在设备中无法滚动 期待您的回复。 谢谢。使用这是代码 xml代码 <ScrollView android:scrollbars="vertical" android:layout_height="wrap_content" android:layout_width="fill_
<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>
雷迪P:谢谢你绝对完美的回答。我在ScrollView中缺少LinearLayout,所以我删除了作为ScrollView的根布局,并使用了LinearLayout,效果很好。但是,如果根布局为ScrollView,则WebView的滚动不起作用,也就是说,如果在ScrollView下,任何WebView滚动都不起作用。
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);
}