Exemple #1
0
        protected override void OnLayout(bool changed, int left, int top, int right, int bottom)
        {
            base.OnLayout(changed, left, top, right, bottom);

            if (_oggetti == null || _articleView == null)
            {
                return;
            }

            float scale = (float)Width / (float)MSize.X;

            _articleView.Layout(0, 0, right - left, bottom - top);
            _articleView.BringToFront();

            /*_bgView.Layout(-50, -50, right - left, bottom - top);
             * moveToBack(_bgView);*/

            if (!changed)
            {
                return;
            }

            var oggetti = _oggetti.Values.ToArray();

            for (int j = 0; j < oggetti.Length; j++)
            {
                ObjView ov = (ObjView)oggetti[j];

                RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams((int)((ov.Frame.Right - ov.Frame.Left) * scale), (int)((ov.Frame.Bottom - ov.Frame.Top) * scale));
                lp.LeftMargin = (int)(ov.Frame.Left * scale);
                lp.TopMargin  = (int)(ov.Frame.Top * scale);

                /*lp.Width = (int)((ov.Frame.Right - ov.Frame.Left) * scale);
                 * lp.Height = (int)((ov.Frame.Bottom - ov.Frame.Top) * scale);*/
                ov.LayoutParameters = lp;

                //ov.RequestLayout();
                //ov.Invalidate();

                /*ov.Layout((int)(ov.Frame.Left * scale),
                 *      (int)(ov.Frame.Top * scale),
                 *      (int)(ov.Frame.Right * scale),
                 *      (int)(ov.Frame.Bottom * scale));*/
            }

            oggetti = null;
        }
Exemple #2
0
        protected override void OnLayout(bool changed, int l, int t, int r, int b)
        {
            base.OnLayout(changed, l, t, r, b);

            if (!_firstRun)
            {
                this.ScrollTo((int)_Scroller.ContentX, (int)_Scroller.ContentY);
                _firstRun = true;
            }

            if (_objViews == null || _contentView == null || !changed)
            {
                return;
            }

            float scaleX = (float)Width / (float)_initFrame.Width;
            float scaleY = (float)Height / (float)_initFrame.Height;

            //float scale = System.Math.Min(scaleX, scaleY);
            _zoom = System.Math.Min(scaleX, scaleY);
            //_contentView.SetBackgroundColor(Android.Graphics.Color.Red);

            //this.ScrollTo((int)(ScrollX * _zoom), (int)(ScrollY * _zoom));
            var lp = new ViewGroup.LayoutParams(0, 0);

            if (_contentView != null)
            {
                lp        = _contentView.LayoutParameters;
                lp.Width  = (int)System.Math.Round(_ContentSize.Width * _zoom);
                lp.Height = (int)System.Math.Round(_ContentSize.Height * _zoom);
                _contentView.LayoutParameters = lp;
            }

            if (_backgroundView != null)
            {
                lp        = _backgroundView.LayoutParameters;
                lp.Width  = (int)System.Math.Round(_ContentSize.Width * _zoom);
                lp.Height = (int)System.Math.Round(_ContentSize.Height * _zoom);
                _backgroundView.LayoutParameters = lp;
            }

            foreach (View view in _objViews.Values)
            {
                if (view == null)
                {
                    continue;
                }

                ObjView ov = (ObjView)view;

                RelativeLayout.LayoutParams rlp = new RelativeLayout.LayoutParams((int)System.Math.Round((ov.Frame.Right - ov.Frame.Left) * _zoom), (int)System.Math.Round((ov.Frame.Bottom - ov.Frame.Top) * _zoom));
                rlp.LeftMargin      = (int)System.Math.Round(ov.Frame.Left * _zoom);
                rlp.TopMargin       = (int)System.Math.Round(ov.Frame.Top * _zoom);
                rlp.Width           = (int)System.Math.Round((ov.Frame.Right - ov.Frame.Left) * _zoom);
                rlp.Height          = (int)System.Math.Round((ov.Frame.Bottom - ov.Frame.Top) * _zoom);
                ov.LayoutParameters = rlp;
            }

            //int a = mScroller.CurrX;
            //int scrollDeltaX = ComputeScrollDeltaToGetChildRectOnScreen(new Rect((int)(_contentX * _zoom), (int)(_contentX * _zoom), lp.Width, lp.Height));

            Log.Info(TAG, "Scroll x=" + mScroller.CurrX + " y=" + mScroller.CurrY);

            //SmoothScrollBy(scrollDeltaX, scrollDeltaX);
        }
Exemple #3
0
        public void ToggleObject(string direction)
        {
            ObjView parent = this.Parent as ObjView;
            //parent.SetBackgroundColor(Android.Graphics.Color.Red);
            RectangleF frame  = new RectangleF(this.GetX(), this.GetY(), this.Width, this.Height);           //this._initFrame;
            RectangleF sFrame = new RectangleF(parent.GetX(), parent.GetY(), parent.Width, parent.Height);

            System.Drawing.Point offset = new System.Drawing.Point(ComputeHorizontalScrollOffset(), ComputeVerticalScrollOffset());

            if (!_Opened)
            {
                _openedDirection = direction;
            }
            else
            {
                direction = _openedDirection;
            }

            switch (direction)
            {
            case "top":
                if (_Opened)
                {
                    frame.Height  = _initFrame.Height * _zoom;
                    sFrame.Height = _initFrame.Height * _zoom;

                    sFrame.Y = _parentFrame.Y * _zoom;                            //_parentFrame.Y;
                    _Opened  = false;
                }
                else
                {
                    float contentH = ComputeVerticalScrollRange() > 0 ? ComputeVerticalScrollRange() : _ContentSize.Height;

                    frame.Height = sFrame.Height = contentH;
                    sFrame.Y    -= contentH - _initFrame.Height;

                    _Opened = true;
                }
                break;

            case "bottom":
                if (_Opened)
                {
                    frame.Height  = _initFrame.Height * _zoom;
                    sFrame.Height = _initFrame.Height * _zoom;
                    offset.Y      = (int)_contentY;
                    _Opened       = false;
                }
                else
                {
                    float contentH = ComputeVerticalScrollRange() > 0 ? ComputeVerticalScrollRange() : _ContentSize.Height;

                    frame.Height = sFrame.Height = contentH;
                    offset.Y     = (int)_Scroller.ContentY;

                    /*RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams((int)frame.Width, (int)frame.Height);
                     * lp.LeftMargin = (int)frame.X;
                     * lp.TopMargin = (int)frame.Y;
                     * this.LayoutParameters = lp;*/

                    //this.ContentOffset = offset;
                    ScrollTo(offset.X, offset.Y);
                    offset.Y = 0;
                    _Opened  = true;
                }
                break;

            case "left":
                if (_Opened)
                {
                    frame.Width  = _initFrame.Width * _zoom;
                    sFrame.Width = _initFrame.Width * _zoom;
                    sFrame.X     = _parentFrame.X * _zoom;
                    _Opened      = false;
                }
                else
                {
                    float contentW = ComputeHorizontalScrollRange() > 0 ? ComputeHorizontalScrollRange() : _ContentSize.Width;

                    frame.Width = sFrame.Width = contentW;
                    sFrame.X   -= (contentW - _initFrame.Width);

                    _Opened = true;
                }
                break;

            case "right":
                if (_Opened)
                {
                    frame.Width  = _initFrame.Width * _zoom;
                    sFrame.Width = _initFrame.Width * _zoom;
                    offset.X     = (int)(_contentX * _zoom);

                    _Opened = false;
                }
                else
                {
                    float contentW = ComputeHorizontalScrollRange() > 0 ? ComputeHorizontalScrollRange() : _ContentSize.Width;

                    frame.Width = sFrame.Width = contentW;
                    offset.X    = (int)(_Scroller.ContentX * _zoom);
                    offset.X    = 0;

                    _Opened = true;
                }
                break;

            default:
                break;
            }

            //TransformAnimation animation = new TransformAnimation(parent, sFrame);

            /*TransformAnimation animation = new TransformAnimation(parent, sFrame, p =>
             * {
             *      float deltaOffsetX = offset.X - ComputeHorizontalScrollOffset();
             *      float deltaOffsetY = offset.Y - ComputeVerticalScrollOffset();
             *
             *      int offX = (int)(ComputeHorizontalScrollOffset() + deltaOffsetX * (float)p);
             *      int offY = (int)(ComputeVerticalScrollOffset() + deltaOffsetY * (float)p);
             *
             *      this.ScrollTo(offX, offY);
             *
             *      float deltaW = sFrame.Width - parent.Width;
             *      float deltaH = sFrame.Height - parent.Height;
             *      float deltaX = sFrame.X - parent.GetX();
             *      float deltaY = sFrame.Y - parent.GetY();
             *
             *      int w = (int)(parent.Width + deltaW * ((float)p));
             *      int h = (int)(parent.Height + deltaH * ((float)p));
             *      int x = (int)(parent.GetX() + deltaX * ((float)p));
             *      int y = (int)(parent.GetY() + deltaY * ((float)p));
             *
             *      RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(w, h);
             *      lp.LeftMargin = x;
             *      lp.TopMargin = y;
             *
             *      parent.LayoutParameters = lp;
             * });
             *
             * animation.FillAfter = true;
             * animation.Duration = 500;
             * animation.Interpolator = new AccelerateInterpolator(1);
             * parent.Animation = animation;
             *
             * _animating = true;
             * animation.AnimationEnd += delegate
             * {
             *      parent.Frame = new Rect((int)(sFrame.Left/_zoom), (int)(sFrame.Top/_zoom), (int)(sFrame.Right/_zoom), (int)(sFrame.Bottom/_zoom));
             * };
             *
             * animation.StartNow ();*/

            RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams((int)sFrame.Width, (int)sFrame.Height);
            lp.LeftMargin = (int)sFrame.Left;
            lp.TopMargin  = (int)sFrame.Top;

            parent.LayoutParameters = lp;
            parent.Frame            = new Rect((int)(sFrame.Left / _zoom), (int)(sFrame.Top / _zoom), (int)(sFrame.Right / _zoom), (int)(sFrame.Bottom / _zoom));

            PostDelayed(() =>
            {
                this.ScrollTo(offset.X, offset.Y);
            }, 1);
        }