大马资讯论坛 - 马来西亚中文资讯平台

标题: [解決] Android 图片在WebView显示太宽了,超出荧幕,好难看 [打印本页]

作者: 资讯王    时间: 2014-4-13 15:36
标题: [解決] Android 图片在WebView显示太宽了,超出荧幕,好难看
Android's WebView automatically resize huge images
Android WebView, Scaling Image to fit the screen
android - Fit image in webview

1. Add css below in your page 在你的网页加入以下css
  1. <style>
  2. img
  3. {
  4. width:100%;
  5. max-width:100%;
  6. }
  7. </style>
复制代码
2. Go to your android WebView setLayoutAlgorithm 设置你的Webview
  1. WebView oTextView = (WebView) oCurrentActivity.findViewById(R.id.oTextView );
  2. oTextView.getSettings().setDefaultTextEncodingName("UTF-8") ;
  3. oTextView.getSettings().setJavaScriptCanOpenWindowsAutomatically(false);
  4. oTextView.getSettings().setSupportMultipleWindows(false);
  5. oTextView.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
复制代码





欢迎光临 大马资讯论坛 - 马来西亚中文资讯平台 (http://www.freeinfo.com.my/) Powered by Discuz! X3.3