Android:在webview中使用url显示图像时出现问题

Akr*_*ram 2 android webview imageview

我在他的网址的帮助下在我的网页浏览中显示了一些图像,我希望它们位于可用空间的中心,但图像在顶部对齐,还有一件事我正在动态创建webview以在viewpager中显示.实际上我我正在尝试实现应该像Android设备的Facebook应用程序中当前可用的功能.

谢谢.

byt*_*der 5

你应该能够用html包装图像并通过css将它们居中.在我的一个应用程序中完成它.

public class YourActivity extends Activity {

private static final String HTML_FORMAT = "<html><body style=\"text-align: center; background-color: black; vertical-align: center;\"><img src = \"%s\" /></body></html>";
private WebView mWebView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    mWebView = (WebView) findViewById(R.id.yourWebView);

    final String imgUrl = "http://db.tt/2283dXLT";
    final String html = String.format(HTML_FORMAT, imgUrl);

    mWebView.loadDataWithBaseURL("", html, "text/html", "UTF-8", "");
    }
}
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助

您应该只需更改imgUrl即可显示任意数量的图像.