从WebView中的URL加载图像(垂直居中) [英] Load image from url in WebView ( center vertically )
本文介绍了从WebView中的URL加载图像(垂直居中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将尝试在Web视图中加载图像,但是图像应位于顶部,并且我需要它们的方向垂直居中。
I'll try load image in a webview, but the image is position in top, and i need that their orientation is center vertically.
这是代码:
。
。
。
. . .
mStringUrl = getIntent().getExtras().getString(ARGS_IMAGE_URL);
。
。
。
. . .
private void initializeWebView() {
mWebView.loadDataWithBaseURL(null, "<html><head><style>img {margin-top:auto;margin-bottom:auto}</style></head><body><img src=\"" + mStringUrl + "\"></body></html>", "html/css", "utf-8", null);
WebSettings settings = mWebView.getSettings();
settings.setUseWideViewPort(true);
settings.setLoadWithOverviewMode(true);
mWebView.setBackgroundColor(getResources().getColor(R.color.transparent));
mWebView.setWebViewClient(new CustomWebViewClient());
}
xml文件:
<include layout="@layout/layout_toolbar" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:background="@color/black_midnight" />
<ProgressBar
android:layout_width="50dp"
android:layout_height="50dp"
android:visibility="gone"
style="@android:style/Widget.Material.ProgressBar.Small"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
如有任何想法请帮助我,谢谢。
If any have idea please help me, Thanks in advance.
推荐答案
尝试以下代码:
mWebView.loadDataWithBaseURL(null, "<html><head></head><body><table style=\"width:100%; height:100%;\"><tr><td style=\"vertical-align:middle;\"><img src=\"" + mStringUrl + "\"></td></tr></table></body></html>", "html/css", "utf-8", null);
这篇关于从WebView中的URL加载图像(垂直居中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文