How to create an object in the exact location of a coordinate?

0

I have this method that is called when I click on ImageView

private void _imgRoute_Touch(object sender, View.TouchEventArgs e)
{
   if (_examStarted)
   {
      if (e.Event.Action == MotionEventActions.Down)
      {
        float x = e.Event.GetX();
        float y = e.Event.GetY();

        CreateSquare(x, y);

        Toast.MakeText(this, $" {x.ToString()} {y.ToString()}", ToastLength.Short).Show();
      }
   }            
}

It takes the coordinates of the touch. I want to create a small square (it can be ImageView with background-color and height and width 50 for example.

I've tried the following: (it's the CreateSquare method)

var ImgPoint = new ImageView(this);
imgPoint.LayoutParameters.Height = 50;
imgPoint.LayoutParameters.Width = 50;
imgPoint.SetZ(10);
imgPoint.SetX(x);
imgPoint.SetY(y);
LinearLayout ll = (LinearLayout)FindViewById(Resource.Id.mainLinearLayout)
ll.AddView(imgPoint);

Unsuccessful.

What am I missing?

    
asked by anonymous 27.07.2018 / 22:21

0 answers