Android webView自适应屏幕显示图片

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zhuxu820_/article/details/51313446
// css
	public static final String APP_CSS = "<style> html, body{ margin:0; padding:1px; color:#666666; font-style:normal; font-weight:normal; font-size:13px;} div, dl, dt, dd, h1, h2, h3, h4, h5, h6, pre, code, form, fieldset, legend, input, button, textarea, select, p, blockquote, th, td, ol, ul, li{ width:auto; margin:0; padding:0; color:#666666; font-style:normal; font-weight:normal; font-size:13px;} fieldset, img{ border:0;} address, button, caption, cite, code, dfn, em, input, optgroup, option, select, strong, textarea, th, var, span{  font : inherit; color:#666666; font-style:normal; font-weight:normal;} del, ins{ text-decoration:none;} ol, ul, dl{margin-left : 15px;} ol{ list-style:decimal outside;} ul{ list-style:disc outside;} li{ margin:0; padding:0; width:auto; color:#666666; font-style:normal; font-weight:normal; text-indent:-3px; font-size:13px;} h1, h2, h3, h4, h5, h6{ width:auto; font-size:100%; font-weight:normal;} abbr, acronym{ border:0; font-variant:normal;} a, a:link, a:visited, a:hover, a:active{ text-decoration:none; color:#666666} table{ border-collapse:collapse; border-spacing:0; width:auto;} table{ width:100%; border:1px solid #666; } table td, table th, tbody td, tbody th{ width:auto; padding:3px; border:1px solid #c1c1c1; } strong{font-weight:bold} </style>";


只需要在要显示的Html字符串后 添加 这段 代码  便可实现自适应


如果有问题 可重写webView  通过重写 onMeasure 来 设置webView为不可滚动  然后在webView外围添加 ScrollView

@Override
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
				MeasureSpec.AT_MOST);
		super.onMeasure(widthMeasureSpec, expandSpec);
	}


猜你喜欢

转载自blog.csdn.net/zhuxu820_/article/details/51313446