我正在将图像加载到我的 web 视图中,然后单击显示它。由于我在点击之前加载了 webview,我希望图像能够立即显示。但是加载需要一秒钟。如何让图像立即显示。这是我的代码:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
final WebView webView = new WebView(this);
String url = "http://upload.wikimedia.org/wikipedia/commons/d/d8/Deerfire_high_res_edit.jpg";
String html = "<!doctype html><html lang='en'><head></head><body>Hello World<img src='" + url + "'></body></html>";
webView.loadDataWithBaseURL("", html, "text/html", "UTF-8", "");
Button button = new Button(this);
button.setText("Click me!");
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
setContentView(webView);
}
});
layout.addView(button);
setContentView(layout);
}