簡體   English   中英

加載數據高度和寬度以適合Android Webview中的屏幕

[英]Load data Height and width fit to screen in Android Webview

我正在嘗試在Webview中加載視頻。 工作正常。

但是,我的視頻尺寸很小。

我的代碼如下:

webView.loadData("<html><body> <script type='text/javascript'>ch='" + ChId + "'; ch_width=1080; ch_height=720;</script><script type='text/javascript' src='http://m.s247.tv/live.js'></script> </body></html>", "text/html; charset=utf-8", "UTF-8");

我希望視頻適合屏幕。

獲取顯示的寬度和高度。

DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
int width = displayMetrics.widthPixels;
int height = displayMetrics.heightPixels;

然后在Web視圖中,設置寬度和高度:

webView.loadData("<html><body> <script type='text/javascript'>ch='" + ChId + "'; ch_width="+ width +"; ch_height=" + height" +";</script><script type='text/javascript' src='http://m.s247.tv/live.js'></script> </body></html>", "text/html; charset=utf-8", "UTF-8");

您也可以計算縱橫比,並將高度設置為縱橫比。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM