/// <summary> /// Sets up some of the local variables as well as Intrinsic and gesture detector /// </summary> private void InitializeElement() { SetScaleType(ScaleType.Matrix); _matrix = new Matrix(); // If the current element is drawable if (Drawable != null) { _translationSize = new Size(Drawable.IntrinsicHeight, Drawable.IntrinsicWidth); SetOnTouchListener(this); } _gestureDetector = new GestureDetector(_context, new CustomImageViewGestureDetector(this)); //SetAdjustViewBounds(true); }
protected override bool SetFrame(int l, int t, int r, int b) { _elementSize = new Size(r - l, b - t); _matrix.Reset(); var r_norm = r - l; _scale = r_norm/(float) _translationSize.Width; var paddingHeight = 0; var paddingWidth = 0; if (_scale*_translationSize.Height > _elementSize.Height) { _scale = _translationSize.Width/(float) _translationSize.Height; _matrix.PostScale(_scale, _scale); paddingWidth = (r - _elementSize.Width)/2; } else { _matrix.PostScale(_scale, _scale); paddingHeight = (b - _elementSize.Height)/2; } _matrix.PostTranslate(paddingWidth, paddingHeight); ImageMatrix = _matrix; _minScale = _scale; ZoomTo(_elementSize.Width/2, _elementSize.Height/2, _scale); PostTransitionCutting(); return base.SetFrame(l, t, r, b); }