【发布时间】:2012-03-19 00:20:38
【问题描述】:
我的应用程序使用带有透明背景的WebView,其中元素的一些样式属性由 JavaScript 修改。
问题:WebView没有根据修改后的属性刷新。当WebView 被重绘时(例如,由于用户方向改变)WebView 被正确更新。
我在 Android 3.2(三星 GT)上重现了该问题,但在 Android 2.1 和 4.3 上一切正常。
重现问题的示例代码:
显然,当第一个图像被点击时它应该消失,然后点击第二个应该移动它。如果WebView 的背景颜色更改为不透明,或者如果我删除WebView 下方显示的图像,一切正常...
网页视图加载的 HTML。 :
<!DOCTYPE html>
<html>
<body >
<img style="position:absolute;left:0px" onclick="this.style.display='none';"
src="http://flv.justad.tv/gallery/assets/trickplay/justad/tp-pause.png" />
<img style="position:absolute;left:200px" onclick="this.style.top='200px';"
src="http://flv.justad.tv/gallery/assets/trickplay/justad/tp-ff.png" />
</body>
</html>
布局文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitXY"
android:src="@drawable/display_background" />
<RelativeLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/WebviewContainer">
</RelativeLayout>
</RelativeLayout>
应用Activity:
public class TestImageMoveActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
RelativeLayout webviewContainer =
(RelativeLayout)findViewById(R.id.WebviewContainer);
WebView web = new WebView(this);
web.getSettings().setJavaScriptEnabled(true);
web.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
web.setLayoutParams(
new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
web.setBackgroundColor(Color.TRANSPARENT);
webviewContainer.addView(web);
web.loadUrl("http://192.168.1.12/myWeb/localTmp/testImageMove.html");
}
}
点击前的屏幕截图:
【问题讨论】:
-
您的屏幕截图链接已损坏(权限被拒绝)。
-
抱歉...链接现在应该可以使用了
-
不用道歉,只是说你注意到了。 :)
-
看看这个链接它会给你一些想法stackoverflow.com/questions/2563325/…
标签: android android-widget android-webview