Jak utworzyć zaznaczalny okrągły kod ImageView
, tak jak w bieżącej aplikacji Google+ używanej do zdjęć profilowych?Wybieralny widok kołowy, taki jak Google+
To, co odnosi się do:
Powyższy obraz jest zaznaczone, a poniżej jest zaznaczona.
próbuję replikować zdjęcia profilowe 1 do 1.
Moja praca do tej pory:
loadedImage
jest Bitmap
który jest wyświetlany
mImageView.setBackground(createStateListDrawable());
mImageView.setImageBitmap(createRoundImage(loadedImage));
stosowanych metod:
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;
}
Rozmiar urządzenia ImageView
to imageSizePx
, a jego rozmiar to imageSizePx - 3
. Oznacza to, że tło powinno nakładać się na obraz. Co nie działa.
Got zrzut ekranu, co masz na myśli? – CommonsWare
może to pomoże. http://stackoverflow.com/questions/13108803/android-circle-menu-like-catch-notes – cgTag
@CommonsWare Poczekaj chwilę. – Leandros