我将尝试在 Webview 中加载图像,但是图像位于顶部,我需要它们的方向在垂直中心。
这是代码:
. . .
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>
如果有任何想法,请帮助我,谢谢。