Android精简小笔记(4):解析html格式的字符串

如果没有图片则用:
title.setText(Html.fromHtml(title_temp));
如果有图片则用:
content.setText(Html.fromHtml(contentResult, new Html.ImageGetter() {
			@Override
			public Drawable getDrawable(String source) {
				Drawable drawable = null;
				Log.d("Image Path", source);
				try {
					HttpGet httpRequest = new HttpGet(source);
					HttpClient httpclient = new DefaultHttpClient(); 
					HttpResponse response = (HttpResponse) httpclient.execute(httpRequest); 
					HttpEntity entity = response.getEntity(); 
					BufferedHttpEntity bufferedHttpEntity = new BufferedHttpEntity(entity); 
					InputStream is = bufferedHttpEntity.getContent(); 
					drawable = Drawable.createFromStream(is, ""); 
				} catch (Exception e) {
					return null;
				}
				if(drawable==null){
					return null;
				}else{
					int width=ZhiYeDetailActivity.this.getWindow().getWindowManager().getDefaultDisplay().getWidth()-20;	Log.e("ddddddddd",(int)(width*drawable.getIntrinsicHeight()/drawable.getIntrinsicWidth())+"--");
drawable.setBounds(0,0, width-10,(int)(width*drawable.getIntrinsicHeight()/drawable.getIntrinsicWidth()));
					 return drawable;
				}
			}
		}, null));

 

你可能感兴趣的:(Android精简小笔记(4):解析html格式的字符串)