不可能だとは思ってますが、念の為、確認したいです。
androidのwebviewで画像などがレンダリングされなかったところを透明にして、
なおかつ、webviewの後ろの青いviewが透けて見えるようにしたいです。
例えば、上の画像でいうとa,bの部分は青viewが見えてほしいです。
webview内の画像は可変するので
webviewのサイズを固定にすることはできません。
以下確認したサンプルです。
activity_main.xml
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="20dp" android:paddingLeft="20dp" android:paddingRight="20dp" android:paddingTop="20dp" android:background="#0000ff" > <WebView android:id="@+id/webview" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" /> </LinearLayout>
MainActivity.java
WebView webview = new WebView(this); webview = (WebView)this.findViewById(R.id.webview); webview.setWebViewClient(new WebViewClient()); String summary = "<html><body><div style='width:300px;height:400px;text-align:center;vertical-align: middle;display:table-cell;' >" + "<img width='200px' src='https://teratail-v2.storage.googleapis.com/uploads/contributed_images/b1972fa8583bbb5a1a0234fcc6ec1ec2.jpeg' />" + "</div></body></html>"; webview.loadData(summary, "text/html", null);
回答1件
あなたの回答
tips
プレビュー