So, i completed answer from here so it can solve my problem.
XML:
<RoundedThumb
android:layout_width="match_parent"
android:layout_height="match_parent"/>
JAVA:
public class RoundedThumb extends ImageView {
private final float radius = getContext().getResources().getDimension(R.dimen.corner_radius);
private RectF mSrcRect = new RectF();
private RectF mDstRect = new RectF();
private Path mClipPath = new Path();
public RoundedThumb(Context context) {
super(context);
}
public RoundedThumb(Context context, AttributeSet attrs) {
super(context, attrs);
}
public RoundedThumb(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
protected void onDraw(Canvas canvas) {
if (getDrawable() != null && getImageMatrix() != null) {
mSrcRect.set(0, 0, getDrawable().getIntrinsicWidth(), getDrawable().getIntrinsicHeight());
getImageMatrix().mapRect(mDstRect, mSrcRect);
mClipPath.reset();
mClipPath.addRoundRect(mDstRect, radius, radius, Path.Direction.CW);
canvas.clipPath(mClipPath);
}
super.onDraw(canvas);
}
}
And usage:
thumb.setScaleType(ImageView.ScaleType.FIT_CENTER);
Bitmap thumbnail = BitmapFactory.decodeFile(path);
thumb.setImageBitmap(thumbnail);
So, now rect for Path transformed just like BitmapDrawable inside of ImageView and always circumscribed exactly around any bitmap in ImageView. What is important for me - ImageView still has aspectRatio 16/9 and takes it's place, defined in resources. But bitmap has rounded borders, while it is not modified.
UPD1: I am a little bit confused: unfortunately on some devices clipPath method has no effect (SII) or even crashes (old asus transformer). Can be fixed completely by setting hardwareAccelerated
to false
. But, damn, that's not good =/