예제 #1
0
        private void InitGreenDot()
        {
            try
            {
                var l = new MyVtoOnGlobalLayoutListener();
                l.GlobalLayoutEvent += (s, e) =>
                {
                    _mapSwitcher.ViewTreeObserver.RemoveOnGlobalLayoutListener(l);

                    var viewLeft = _mapSwitcher.Left;
                    var viewTop  = _mapSwitcher.Top + _mapSwitcher.Height / 3;

                    const int border = 100;
                    var       xRange = Math.Max(1, _mapSwitcher.Width - border * 2);
                    var       yRange = Math.Max(1, _mapSwitcher.Height / 3 * 2 - border * 2);

                    var rnd = new System.Random();

                    for (int i = 0, cnt = _dotCoords.GetLength(0); i < cnt; i++)
                    {
                        _dotCoords[i, 0] = viewLeft + border + rnd.Next(xRange);
                        _dotCoords[i, 1] = viewTop + border + rnd.Next(yRange);
                    }

                    _greenDot = FindViewById <View>(R.Id.green_dot);
                    _greenDot.SetX(_dotCoords[0, 0]);
                    _greenDot.SetY(_dotCoords[0, 1]);
                };
                _mapSwitcher.ViewTreeObserver.AddOnGlobalLayoutListener(l);
            }
            catch (Exception exc) when(exc is IndexOutOfRangeException)
            {
                LogW(exc.Message);
            }
        }
예제 #2
0
 public void SetContent([DrawableRes] int resId)
 {
     if (_viewWidth == 0)
     {
         var l = new MyVtoOnGlobalLayoutListener();
         l.GlobalLayoutEvent += (s, e) =>
         {
             ItemView.ViewTreeObserver.RemoveOnGlobalLayoutListener(l);
             _viewWidth  = ItemView.Width;
             _viewHeight = ItemView.Height;
             LoadBitmap(resId);
         };
         ItemView.ViewTreeObserver.AddOnGlobalLayoutListener(l);
     }
     else
     {
         LoadBitmap(resId);
     }
 }