{"action":"created","issue":{"url":"https://api.github.com/repos/bumptech/glide/issues/800","labels_url":"https://api.github.com/repos/bumptech/glide/issues/800/labels{/name}","comments_url":"https://api.github.com/repos/bumptech/glide/issues/800/comments","events_url":"https://api.github.com/repos/bumptech/glide/issues/800/events","html_url":"https://github.com/bumptech/glide/issues/800","id":121167343,"number":800,"title":"Glide placeholder question","user":{"login":"shingohu","id":4944887,"avatar_url":"https://avatars.githubusercontent.com/u/4944887?v=3","gravatar_id":"","url":"https://api.github.com/users/shingohu","html_url":"https://github.com/shingohu","followers_url":"https://api.github.com/users/shingohu/followers","following_url":"https://api.github.com/users/shingohu/following{/other_user}","gists_url":"https://api.github.com/users/shingohu/gists{/gist_id}","starred_url":"https://api.github.com/users/shingohu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shingohu/subscriptions","organizations_url":"https://api.github.com/users/shingohu/orgs","repos_url":"https://api.github.com/users/shingohu/repos","events_url":"https://api.github.com/users/shingohu/events{/privacy}","received_events_url":"https://api.github.com/users/shingohu/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/bumptech/glide/labels/duplicate","name":"duplicate","color":"cccccc"},{"url":"https://api.github.com/repos/bumptech/glide/labels/question","name":"question","color":"d4c5f9"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-12-09T06:03:50Z","updated_at":"2015-12-10T01:59:01Z","closed_at":"2015-12-09T13:10:59Z","body":"I want to show a roundedimage so I use this https://github.com/vinc3m1/RoundedImageView \r\nin my xml \r\n\r\n```xml\r\n<com.makeramen.roundedimageview.RoundedImageView\r\n    android:id=\"@+id/item_profile_image\"\r\n    android:layout_width=\"40dip\"\r\n    android:layout_height=\"40dp\"\r\n    android:layout_alignParentLeft=\"true\"\r\n    android:layout_marginLeft=\"10dp\"\r\n    android:layout_marginTop=\"10.0dip\"\r\n    android:scaleType=\"centerCrop\"\r\n    android:src=\"@drawable/avatar_regular\"\r\n    app:riv_corner_radius=\"40dp\"/>\r\n```\r\n\r\nand glide use like this\r\n```java\r\nGlide.with(context).load(url).crossFade().diskCacheStrategy(DiskCacheStrategy.RESULT).centerCrop().placeholder(R.drawable.avatar_regular).into(iv);\r\n```\r\n\r\nwhen the listView load but the image can not show direct,but when I scroll back it show\r\nif i dont set placeholder,There is no problem"},"comment":{"url":"https://api.github.com/repos/bumptech/glide/issues/comments/163462266","html_url":"https://github.com/bumptech/glide/issues/800#issuecomment-163462266","issue_url":"https://api.github.com/repos/bumptech/glide/issues/800","id":163462266,"user":{"login":"chongzi","id":1733826,"avatar_url":"https://avatars.githubusercontent.com/u/1733826?v=3","gravatar_id":"","url":"https://api.github.com/users/chongzi","html_url":"https://github.com/chongzi","followers_url":"https://api.github.com/users/chongzi/followers","following_url":"https://api.github.com/users/chongzi/following{/other_user}","gists_url":"https://api.github.com/users/chongzi/gists{/gist_id}","starred_url":"https://api.github.com/users/chongzi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chongzi/subscriptions","organizations_url":"https://api.github.com/users/chongzi/orgs","repos_url":"https://api.github.com/users/chongzi/repos","events_url":"https://api.github.com/users/chongzi/events{/privacy}","received_events_url":"https://api.github.com/users/chongzi/received_events","type":"User","site_admin":false},"created_at":"2015-12-10T01:59:01Z","updated_at":"2015-12-10T01:59:01Z","body":"as @TWiStErRob  said,you maybe use CirCleCrop, other way is use follow CirlCleImageView . my test show success.\r\n\r\n\r\nimport android.content.Context;\r\nimport android.content.res.TypedArray;\r\nimport android.graphics.Bitmap;\r\nimport android.graphics.BitmapShader;\r\nimport android.graphics.Canvas;\r\nimport android.graphics.Color;\r\nimport android.graphics.ColorFilter;\r\nimport android.graphics.Matrix;\r\nimport android.graphics.Paint;\r\nimport android.graphics.RectF;\r\nimport android.graphics.Shader;\r\nimport android.graphics.drawable.BitmapDrawable;\r\nimport android.graphics.drawable.ColorDrawable;\r\nimport android.graphics.drawable.Drawable;\r\nimport android.net.Uri;\r\nimport android.support.annotation.ColorRes;\r\nimport android.support.annotation.DrawableRes;\r\nimport android.util.AttributeSet;\r\nimport android.widget.ImageView;\r\n\r\nimport com.nfdaily.nfplus.R;\r\n\r\npublic class CircleImageView extends ImageView {\r\n\r\n\tprivate static final ScaleType SCALE_TYPE = ScaleType.CENTER_CROP;\r\n\r\n\tprivate static final Bitmap.Config BITMAP_CONFIG = Bitmap.Config.ARGB_8888;\r\n\tprivate static final int COLORDRAWABLE_DIMENSION = 2;\r\n\r\n\tprivate static final int DEFAULT_BORDER_WIDTH = 0;\r\n\tprivate static final int DEFAULT_BORDER_COLOR = Color.BLACK;\r\n\tprivate static final boolean DEFAULT_BORDER_OVERLAY = false;\r\n\r\n\tprivate final RectF mDrawableRect = new RectF();\r\n\tprivate final RectF mBorderRect = new RectF();\r\n\r\n\tprivate final Matrix mShaderMatrix = new Matrix();\r\n\tprivate final Paint mBitmapPaint = new Paint();\r\n\tprivate final Paint mBorderPaint = new Paint();\r\n\r\n\tprivate int mBorderColor = DEFAULT_BORDER_COLOR;\r\n\tprivate int mBorderWidth = DEFAULT_BORDER_WIDTH;\r\n\r\n\tprivate Bitmap mBitmap;\r\n\tprivate BitmapShader mBitmapShader;\r\n\tprivate int mBitmapWidth;\r\n\tprivate int mBitmapHeight;\r\n\r\n\tprivate float mDrawableRadius;\r\n\tprivate float mBorderRadius;\r\n\r\n\tprivate ColorFilter mColorFilter;\r\n\r\n\tprivate boolean mReady;\r\n\tprivate boolean mSetupPending;\r\n\tprivate boolean mBorderOverlay;\r\n\r\n\tpublic CircleImageView(Context context) {\r\n\t\tsuper(context);\r\n\r\n\t\tinit();\r\n\t}\r\n\r\n\tpublic CircleImageView(Context context, AttributeSet attrs) {\r\n\t\tthis(context, attrs, 0);\r\n\t}\r\n\r\n\tpublic CircleImageView(Context context, AttributeSet attrs, int defStyle) {\r\n\t\tsuper(context, attrs, defStyle);\r\n\r\n\t\tTypedArray a = context.obtainStyledAttributes(attrs,\r\n\t\t\t\tR.styleable.CircleImageView, defStyle, 0);\r\n\r\n\t\tmBorderWidth = a.getDimensionPixelSize(\r\n\t\t\t\tR.styleable.CircleImageView_border_width, DEFAULT_BORDER_WIDTH);\r\n\t\tmBorderColor = a.getColor(R.styleable.CircleImageView_border_color,\r\n\t\t\t\tDEFAULT_BORDER_COLOR);\r\n\t\tmBorderOverlay = a.getBoolean(\r\n\t\t\t\tR.styleable.CircleImageView_border_overlay,\r\n\t\t\t\tDEFAULT_BORDER_OVERLAY);\r\n\r\n\t\ta.recycle();\r\n\r\n\t\tinit();\r\n\t}\r\n\r\n\tprivate void init() {\r\n\t\tsuper.setScaleType(SCALE_TYPE);\r\n\t\tmReady = true;\r\n\r\n\t\tif (mSetupPending) {\r\n\t\t\tsetup();\r\n\t\t\tmSetupPending = false;\r\n\t\t}\r\n\t}\r\n\r\n\t@Override\r\n\tpublic ScaleType getScaleType() {\r\n\t\treturn SCALE_TYPE;\r\n\t}\r\n\r\n\t@Override\r\n\tpublic void setScaleType(ScaleType scaleType) {\r\n\t\tif (scaleType != SCALE_TYPE) {\r\n\t\t\tthrow new IllegalArgumentException(String.format(\r\n\t\t\t\t\t\"ScaleType %s not supported.\", scaleType));\r\n\t\t}\r\n\t}\r\n\r\n\t@Override\r\n\tpublic void setAdjustViewBounds(boolean adjustViewBounds) {\r\n\t\tif (adjustViewBounds) {\r\n\t\t\tthrow new IllegalArgumentException(\r\n\t\t\t\t\t\"adjustViewBounds not supported.\");\r\n\t\t}\r\n\t}\r\n\r\n\t@Override\r\n\tprotected void onDraw(Canvas canvas) {\r\n\t\tif (getDrawable() == null) {\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\tcanvas.drawCircle(getWidth() / 2, getHeight() / 2, mDrawableRadius,\r\n\t\t\t\tmBitmapPaint);\r\n\t\tif (mBorderWidth != 0) {\r\n\t\t\tcanvas.drawCircle(getWidth() / 2, getHeight() / 2, mBorderRadius,\r\n\t\t\t\t\tmBorderPaint);\r\n\t\t}\r\n\t}\r\n\r\n\t@Override\r\n\tprotected void onSizeChanged(int w, int h, int oldw, int oldh) {\r\n\t\tsuper.onSizeChanged(w, h, oldw, oldh);\r\n\t\tsetup();\r\n\t}\r\n\r\n\tpublic int getBorderColor() {\r\n\t\treturn mBorderColor;\r\n\t}\r\n\r\n\tpublic void setBorderColor(int borderColor) {\r\n\t\tif (borderColor == mBorderColor) {\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\tmBorderColor = borderColor;\r\n\t\tmBorderPaint.setColor(mBorderColor);\r\n\t\tinvalidate();\r\n\t}\r\n\r\n\tpublic void setBorderColorResource(@ColorRes int borderColorRes) {\r\n\t\tsetBorderColor(getContext().getResources().getColor(borderColorRes));\r\n\t}\r\n\r\n\tpublic int getBorderWidth() {\r\n\t\treturn mBorderWidth;\r\n\t}\r\n\r\n\tpublic void setBorderWidth(int borderWidth) {\r\n\t\tif (borderWidth == mBorderWidth) {\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\tmBorderWidth = borderWidth;\r\n\t\tsetup();\r\n\t}\r\n\r\n\tpublic boolean isBorderOverlay() {\r\n\t\treturn mBorderOverlay;\r\n\t}\r\n\r\n\tpublic void setBorderOverlay(boolean borderOverlay) {\r\n\t\tif (borderOverlay == mBorderOverlay) {\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\tmBorderOverlay = borderOverlay;\r\n\t\tsetup();\r\n\t}\r\n\r\n\t@Override\r\n\tpublic void setImageBitmap(Bitmap bm) {\r\n\t\tsuper.setImageBitmap(bm);\r\n\t\tmBitmap = bm;\r\n\t\tsetup();\r\n\t}\r\n\r\n\t@Override\r\n\tpublic void setImageDrawable(Drawable drawable) {\r\n\t\tsuper.setImageDrawable(drawable);\r\n\t\tmBitmap = getBitmapFromDrawable(drawable);\r\n\t\tsetup();\r\n\t}\r\n\r\n\t@Override\r\n\tpublic void setImageResource(@DrawableRes int resId) {\r\n\t\tsuper.setImageResource(resId);\r\n\t\tmBitmap = getBitmapFromDrawable(getDrawable());\r\n\t\tsetup();\r\n\t}\r\n\r\n\t@Override\r\n\tpublic void setImageURI(Uri uri) {\r\n\t\tsuper.setImageURI(uri);\r\n\t\tmBitmap = getBitmapFromDrawable(getDrawable());\r\n\t\tsetup();\r\n\t}\r\n\r\n\t@Override\r\n\tpublic void setColorFilter(ColorFilter cf) {\r\n\t\tif (cf == mColorFilter) {\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\tmColorFilter = cf;\r\n\t\tmBitmapPaint.setColorFilter(mColorFilter);\r\n\t\tinvalidate();\r\n\t}\r\n\r\n\tprivate Bitmap getBitmapFromDrawable(Drawable drawable) {\r\n\t\tif (drawable == null) {\r\n\t\t\treturn null;\r\n\t\t}\r\n\r\n\t\tif (drawable instanceof BitmapDrawable) {\r\n\t\t\treturn ((BitmapDrawable) drawable).getBitmap();\r\n\t\t}\r\n\r\n\t\ttry {\r\n\t\t\tBitmap bitmap;\r\n\r\n\t\t\tif (drawable instanceof ColorDrawable) {\r\n\t\t\t\tbitmap = Bitmap.createBitmap(COLORDRAWABLE_DIMENSION,\r\n\t\t\t\t\t\tCOLORDRAWABLE_DIMENSION, BITMAP_CONFIG);\r\n\t\t\t} else {\r\n\t\t\t\tbitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(),\r\n\t\t\t\t\t\tdrawable.getIntrinsicHeight(), BITMAP_CONFIG);\r\n\t\t\t}\r\n\r\n\t\t\tCanvas canvas = new Canvas(bitmap);\r\n\t\t\tdrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());\r\n\t\t\tdrawable.draw(canvas);\r\n\t\t\treturn bitmap;\r\n\t\t} catch (OutOfMemoryError e) {\r\n\t\t\treturn null;\r\n\t\t}\r\n\t}\r\n\r\n\tprivate void setup() {\r\n\t\tif (!mReady) {\r\n\t\t\tmSetupPending = true;\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\tif (mBitmap == null) {\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\tmBitmapShader = new BitmapShader(mBitmap, Shader.TileMode.CLAMP,\r\n\t\t\t\tShader.TileMode.CLAMP);\r\n\r\n\t\tmBitmapPaint.setAntiAlias(true);\r\n\t\tmBitmapPaint.setShader(mBitmapShader);\r\n\r\n\t\tmBorderPaint.setStyle(Paint.Style.STROKE);\r\n\t\tmBorderPaint.setAntiAlias(true);\r\n\t\tmBorderPaint.setColor(mBorderColor);\r\n\t\tmBorderPaint.setStrokeWidth(mBorderWidth);\r\n\r\n\t\tmBitmapHeight = mBitmap.getHeight();\r\n\t\tmBitmapWidth = mBitmap.getWidth();\r\n\r\n\t\tmBorderRect.set(0, 0, getWidth(), getHeight());\r\n\t\tmBorderRadius = Math.min((mBorderRect.height() - mBorderWidth) / 2,\r\n\t\t\t\t(mBorderRect.width() - mBorderWidth) / 2);\r\n\r\n\t\tmDrawableRect.set(mBorderRect);\r\n\t\tif (!mBorderOverlay) {\r\n\t\t\tmDrawableRect.inset(mBorderWidth, mBorderWidth);\r\n\t\t}\r\n\t\tmDrawableRadius = Math.min(mDrawableRect.height() / 2,\r\n\t\t\t\tmDrawableRect.width() / 2);\r\n\r\n\t\tupdateShaderMatrix();\r\n\t\tinvalidate();\r\n\t}\r\n\r\n\tprivate void updateShaderMatrix() {\r\n\t\tfloat scale;\r\n\t\tfloat dx = 0;\r\n\t\tfloat dy = 0;\r\n\r\n\t\tmShaderMatrix.set(null);\r\n\r\n\t\tif (mBitmapWidth * mDrawableRect.height() > mDrawableRect.width()\r\n\t\t\t\t* mBitmapHeight) {\r\n\t\t\tscale = mDrawableRect.height() / (float) mBitmapHeight;\r\n\t\t\tdx = (mDrawableRect.width() - mBitmapWidth * scale) * 0.5f;\r\n\t\t} else {\r\n\t\t\tscale = mDrawableRect.width() / (float) mBitmapWidth;\r\n\t\t\tdy = (mDrawableRect.height() - mBitmapHeight * scale) * 0.5f;\r\n\t\t}\r\n\r\n\t\tmShaderMatrix.setScale(scale, scale);\r\n\t\tmShaderMatrix.postTranslate((int) (dx + 0.5f) + mDrawableRect.left,\r\n\t\t\t\t(int) (dy + 0.5f) + mDrawableRect.top);\r\n\r\n\t\tmBitmapShader.setLocalMatrix(mShaderMatrix);\r\n\t}\r\n\r\n}"}}