如何ImageView
在用于个人资料图片的当前 Google+ 应用程序中创建一个可选择的循环?
这就是我所指的:
上图未选中,下图已选中。
我尝试以 1 对 1 复制个人资料图片。
到目前为止我的工作:
loadedImage
是Bitmap
显示的
mImageView.setBackground(createStateListDrawable());
mImageView.setImageBitmap(createRoundImage(loadedImage));
使用的方法:
private Bitmap createRoundImage(Bitmap loadedImage) {
Bitmap circleBitmap = Bitmap.createBitmap(loadedImage.getWidth(), loadedImage.getHeight(), Bitmap.Config.ARGB_8888);
BitmapShader shader = new BitmapShader(loadedImage, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setShader(shader);
Canvas c = new Canvas(circleBitmap);
c.drawCircle(loadedImage.getWidth() / 2, loadedImage.getHeight() / 2, loadedImage.getWidth() / 2, paint);
return circleBitmap;
}
private StateListDrawable createStateListDrawable() {
StateListDrawable stateListDrawable = new StateListDrawable();
OvalShape ovalShape = new OvalShape();
ShapeDrawable shapeDrawable = new ShapeDrawable(ovalShape);
stateListDrawable.addState(new int[] { android.R.attr.state_pressed }, shapeDrawable);
stateListDrawable.addState(StateSet.WILD_CARD, shapeDrawable);
return stateListDrawable;
}
的大小ImageView
是imageSizePx
和图像的大小是imageSizePx - 3
。所以,这意味着背景应该与图像重叠。这是行不通的。