android - how to display image with the best way when downloading image -
i wanna display texts , images when apps downloading images (i run activity first time) , happen (it isn't good)
but when app downloaded images happen (i run activity second time) (it's good)
this code :
linearlayout layoutroot = (linearlayout) findviewbyid(r.id.layoutroots); string text = "this image file [loadimage:addlike.png] image [loadimage:adddislike.png] image "; processtext(text, layoutroot, r.layout.image_style, r.layout.text_style); } private void processtext(string text, linearlayout layoutroot,int imagelayout, int textlayout) { pattern pattern = pattern.compile("\\[loadimage:(.*?)\\]"); matcher matcher = pattern.matcher(text); int offset = 0; while (matcher.find()) { try { string textbeforimage = text.substring(offset, matcher.start()); offset += textbeforimage.length(); textbeforimage = textbeforimage.trim(); if (textbeforimage.length() != 0) { addtextview(textbeforimage); } string imagename = matcher.group(1).tostring(); if (imagename.length() != 0) { addimageview(imagename); offset += text.substring(matcher.start(), matcher.end()).length(); } } catch (exception e) { e.printstacktrace(); } } try { if (offset != text.length()) { string content = text.substring(offset).trim(); if (content.length() != 0) { addtextview(content); } } } catch (exception e) { e.printstacktrace(); } } private void addtextview(string text){ view custom = g.layoutinflater.inflate(r.layout.text_style, null); textview tv = (textview) custom.findviewbyid(r.id.mytxt); tv.settext(text); parent.addview(custom); setcontentview(parent); } private void addimageview(string imagename){ view custom = g.layoutinflater.inflate(r.layout.image_style, null); parent.addview(custom); setcontentview(parent); imageview img = (imageview) custom.findviewbyid(r.id.myimg); final file imagefile = new file(g.dir_final + "/" + imagename); if ( !imagefile.exists()) { img.setimagebitmap(null); string link = "http://example.com/images/" + imagename; downloadimage.addtodownloadlist(link, img); } bitmapfactory.options options = new bitmapfactory.options(); //options.insamplesize = 8; bitmap bitmap = bitmapfactory.decodefile(imagefile.getabsolutepath(), options); img.setimagebitmap(bitmap); }
if need image_style or text_style or thing else , tell me
sorry english
Comments
Post a Comment