Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class V extends ImageView {
- public V(Context context) {
- super(context);
- setScaleType(ScaleType.MATRIX);
- }
- @Override
- protected void onSizeChanged(int w, int h, int oldw, int oldh) {
- super.onSizeChanged(w, h, oldw, oldh);
- Drawable d = getDrawable();
- if (d != null) {
- float scale = w / (float) d.getIntrinsicWidth();
- Matrix matrix = new Matrix();
- RectF src = new RectF(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
- RectF dst = new RectF(0, 0, w, h);
- matrix.setRectToRect(src, dst, Matrix.ScaleToFit.CENTER);
- float[] points = {
- 0, d.getIntrinsicHeight()
- };
- matrix.mapPoints(points);
- matrix.postTranslate(0, h - points[1]);
- setImageMatrix(matrix);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement