Advertisement
Guest User

Untitled

a guest
Jan 29th, 2015
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. class V extends ImageView {
  2.  
  3. public V(Context context) {
  4. super(context);
  5. setScaleType(ScaleType.MATRIX);
  6. }
  7.  
  8. @Override
  9. protected void onSizeChanged(int w, int h, int oldw, int oldh) {
  10. super.onSizeChanged(w, h, oldw, oldh);
  11. Drawable d = getDrawable();
  12. if (d != null) {
  13. float scale = w / (float) d.getIntrinsicWidth();
  14. Matrix matrix = new Matrix();
  15. RectF src = new RectF(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
  16. RectF dst = new RectF(0, 0, w, h);
  17. matrix.setRectToRect(src, dst, Matrix.ScaleToFit.CENTER);
  18. float[] points = {
  19. 0, d.getIntrinsicHeight()
  20. };
  21. matrix.mapPoints(points);
  22. matrix.postTranslate(0, h - points[1]);
  23. setImageMatrix(matrix);
  24. }
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement