java - How can I create an image placeholder of an image I am fetching from the web? -


i given image size, , want create placeholder of image size's ratio. simple solid gray color fine.

you can create 1 in code this:

bitmap b = bitmap.createbitmap(width, height, bitmap.config.argb_8888); canvas c = new canvas(b); paint p = new paint(); p.setcolor(color.gray); p.setstyle(paint.style.fill); c.drawrect(0, 0, width, height, p); 

but think it's easier create xml drawable:

<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android">     <solid android:color="#ffcccccc"/> </shape> 

you can set on imageview using r.drawable id, , don't have worry memory use because android handling caching , that.


Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -