Estoy en el desarrollo de una aplicación la cual tiene un widget flotante que se puede mover. Necesito poder mover el widget hacia la izquierda o derecha a modo de animación cuando el usuario lo deje en la mitad de la pantalla, he investigado y tengo el siguiente código para hacer eso (El cual no funciona):
non-public void resetPosition()
{
Timer Timer1 = new Timer();
Timer1.Interval = 150;
Timer1.Enabled = true;
int counter = 5;
Timer1.Begin();
Timer1.Elapsed += (object sender, ElapsedEventArgs e) =>
{
counter--;
var valor = FindViewById<TextView>(Useful resource.Id.aaa);
valor.Textual content = counter;
layoutParams.X = layoutParams.X * counter;
windowManager.UpdateViewLayout(floatingView, layoutParams);
if (counter == 0)
{
Timer1.Cease();
}
};
Este código se llama al momento cuando el usuario deja de presionar el widget. Aquí el código
public bool OnTouch(View v, MotionEvent e)
{
change (e.Motion)
{
case MotionEventActions.Down:
initialX = layoutParams.X;
initialY = layoutParams.Y;
initialTouchX = e.RawX;
initialTouchY = e.RawY;
return true;
case MotionEventActions.Transfer:
layoutParams.X = initialX + (int)(e.RawX - initialTouchX);
layoutParams.Y = initialY + (int)(e.RawY - initialTouchY);
closeFloatingView.Visibility = ViewStates.Seen;
windowManager.UpdateViewLayout(floatingView, layoutParams);
return true;
case MotionEventActions.Up:
closeFloatingView.Visibility = ViewStates.Gone;
initialX = layoutParams.X;
initialY = layoutParams.Y;
resetPosition();
}
return false;
}
También necesito enviar el dato de la variable counter a un textview y me sale error en el FindViewById.
Les agradezco mucho su ayuda.