帖子详情页
客户端请求url,服务器返回数据。主要是怎么把帖子内容中的图片显示出来
我之前把内容中的图片存储为base64编码
var startMark="<img src='data:image/jpeg;base64," var endMark="'/>" if(!content.contains(startMark)) { post_content.text=content }else{ var preStart=0 var start=0 var spanString:SpannableStringBuilder= SpannableStringBuilder() var res="" spanString?.append(content) while(true){ start=content.indexOf(startMark,preStart) var end=content.indexOf(endMark,start) // println(content) if(start!=-1&&end!=-1){ var imgStart=start+startMark.length var base64Url=content.substring(imgStart,end) //println(base64Url) var byteData= Base64.decode(base64Url,Base64.NO_WRAP) var oriBitmap=BitmapFactory.decodeByteArray(byteData,0,byteData.size) var imgSpan=ImageSpan(this,oriBitmap) spanString?.replace(start,end+endMark.length," ") content=content.replace(startMark+base64Url+endMark," ") spanString?.setSpan(imgSpan,start,start+1,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) preStart=start+1 }else{ break } } post_content.text=spanString
这样处理有点low。。。一开始就不应该把图片编码base64存储在数据库中的,应该存图片的地址。。
来源:https://www.cnblogs.com/vocus/p/12602739.html