我想在Web视图中加载图像,但它会在Web视图的top_left处显示所有图像.我的照片在互联网上而非本地.
gifView.loadUrl(mImageUrl);
gifView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
view.getSettings().setLoadsImagesAutomatically(true);
if (mProgressBar != null) {
mProgressBar.setVisibility(View.GONE);
}
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
if (mProgressBar != null) {
mProgressBar.setVisibility(View.VISIBLE);
}
}
});
Run Code Online (Sandbox Code Playgroud)
这是我的xml :::
<WebView
android:id="@+id/gif_image"
android:background="@null"
android:layout_gravity="center"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
Run Code Online (Sandbox Code Playgroud)
编辑:我用过:
String HTML_FORMAT = "<html><body style=\"text-align: center; background-color: null; vertical-align: middle;\"><img src = \"%s\" /></body></html>";
final String html = String.format(HTML_FORMAT, mImageUrl);
gifView.loadDataWithBaseURL("", html, "text/html", "UTF-8", "");
Run Code Online (Sandbox Code Playgroud)
但我的形象只有水平中心,如何居中
Chi*_*rag 10
试试这个.
myWebView.loadData("<html><head><style type='text/css'>body{margin:auto auto;text-align:center;} img{width:100%25;} </style></head><body><img src='www.mysite.com/myimg.jpeg'/></body></html>" ,"text/html", "UTF-8");
Run Code Online (Sandbox Code Playgroud)
试试这个,这将使内容适合您的网络视图
WebView web = (WebView) findViewById(R.id.gif_image);
web.getSettings().setDefaultZoom(ZoomDensity.FAR);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16542 次 |
| 最近记录: |