Forum Xamarin.Android

How do I keep from leaving the screen?

sboinchsboinch Member ✭✭

I do not speak English well.

We apologize if you do not understand the question.

LinearLayout _Main_Contact_Layout;
FrameLayout _Main_Frame; 
ImageView _Main_Background;
private List<string> _DrawerList_Item;
private ListView _DrawerList;

float _X, _Y;
float _XX, _YY;
int offset = 0, duration = 100;
float scaleX = 1.0f, scaleY = 1.0f;
float maxZoomLimit = 2.6f, minZoomLimit = 1.0f;

public bool OnTouch(View v, MotionEvent e)
{
    switch (e.Action)
    {
        case MotionEventActions.Down:

            _X = e.GetX();
            _Y = e.GetY();

            float _Start_X = 760, _Start_Y = 160;
            float _End_X = 1150, _End_Y = 490;

            WindowManagerLayoutParams _Params = new WindowManagerLayoutParams();
            _Params.X = (int)e.RawX;
            _Params.Y = (int)e.RawY;

            LayoutInflater inflater = (LayoutInflater)this.GetSystemService(Context.LayoutInflaterService);
            View _Popup = inflater.Inflate(Resource.Layout.Custom_Popup, null);

            PopupWindow _Window = new PopupWindow(_Popup, WindowManagerLayoutParams.WrapContent, WindowManagerLayoutParams.WrapContent);
            _Window.SetBackgroundDrawable(new BitmapDrawable());
            _Window.OutsideTouchable = true;

            TextView _SetupX = (TextView)_Popup.FindViewById(Resource.Id.x_text);
            TextView _SetupY = (TextView)_Popup.FindViewById(Resource.Id.y_text);

            _SetupX.Text = "X 좌표 : " + _X.ToString("#.##");
            _SetupY.Text = "Y 좌표 : " + _Y.ToString("#.##");

            DrawerLayout _lstDrawer = (DrawerLayout)v.FindViewById(Resource.Id._DrawerLayout);


            if(_Start_X > _X | _Start_Y > _Y | _End_X < _X | _End_Y < _Y )
            {
                _Window.Focusable = true;
                _Window.ShowAsDropDown(_Popup, _Params.X, _Params.Y);
                _Window.ShowAtLocation(_Popup, GravityFlags.Left | GravityFlags.Top, 0, 0);
                _lstDrawer.CloseDrawer((int)GravityFlags.Left);
            }

            else if (_Start_X < _X & _Start_Y < _Y & _End_X > _X & _End_Y > _Y & !_lstDrawer.IsDrawerOpen((int)GravityFlags.Left))
            {
                _lstDrawer.OpenDrawer((int)GravityFlags.Left);
                _Window.ShowAsDropDown(_Popup, _Params.X, _Params.Y);
                _Window.ShowAtLocation(_Popup, GravityFlags.Left | GravityFlags.Top, 0, 0);
            }

            else if (_lstDrawer.IsDrawerOpen((int)GravityFlags.Left))
            {
                _lstDrawer.CloseDrawer((int)GravityFlags.Left);
            }

            break;


        case MotionEventActions.Move:

            _XX = e.GetX() - _X;
            _YY = e.GetY() - _Y;

            //_Main_Background.SetX(_Main_Background.GetX() + _XX);
            //_Main_Background.SetY(_Main_Background.GetY() + _YY);

            _X = e.GetX();
            _Y = e.GetY();


            if (scaleX > 1.0f && scaleY > 1.0f)
            {
                _MoveToX(_XX);
                _MoveToY(_YY);

                Console.WriteLine("_XX : " + _XX.ToString());
                Console.WriteLine("_YY : " + _YY.ToString());
            }

            break;
    }

    return true;
}

private void _MoveToX(float xX)
{
    float futureX = _Main_Background.GetX() + _XX;
    if (futureX > 0 | futureX < 500)
    {
        _Main_Background.SetX(futureX);
    }
}

private void _MoveToY(float yY)
{
    float futureY = _Main_Background.GetY() + _YY;
    if (futureY > 0 | futureY < 500)
    {
        _Main_Background.SetY(futureY);
    }
}



private void _Zoom_In(View v)
{
    if (scaleX < maxZoomLimit && scaleY < maxZoomLimit)
    {
        Animation animation = new ScaleAnimation(scaleX, (scaleX + 0.2f), scaleY, (scaleY + 0.2f), _X, _Y);
        scaleX += 0.2f;
        scaleY += 0.2f;
        animation.Interpolator = new DecelerateInterpolator();
        animation.Duration = duration;
        animation.StartOffset = offset;
        animation.FillAfter = true;
        v.StartAnimation(animation);
    }
}

private void _Zoom_Out(View v)
{
    if (scaleX > minZoomLimit && scaleY > minZoomLimit)
    {
        Animation animation = new ScaleAnimation(scaleX, (scaleX - 0.2f), scaleY, (scaleY - 0.2f), _X, _Y);
        scaleY -= 0.2f;
        scaleX -= 0.2f;
        animation.Interpolator = new DecelerateInterpolator();
        animation.Duration = duration;
        animation.StartOffset = offset;
        animation.FillAfter = true;
        v.StartAnimation(animation);
    }
}

I am worried about this for about a week.

How do I keep from leaving the screen?

Adjusting the scale? How do I touch the scale?

  1. Zoom in and Zoom out using the Button
    -> resolution

  2. Moving images with Zoom in using Button
    -> resolution

  3. If you move it after Zoom in, start with moving the image to a strange place.
    -> resolution

  4. Layout out of range
    -> resolution

  5. Move only within layout range (Unresolved)

Best Answer

Answers

  • WindyhenWindyhen USMember ✭✭

    Hi, Can you limit the x,y by looking at the max width and max height of screen.

    var ScreenHeight = (int) (Resources.DisplayMetrics.HeightPixels / Resources.DisplayMetrics.Density);
    var ScreenWidth = (int) (Resources.DisplayMetrics.WidthPixels / Resources.DisplayMetrics.Density);

  • sboinchsboinch Member ✭✭

    @Windyhen Where do I add it?

Sign In or Register to comment.