Я создал относительный макет, который изменит положение кнопки, когда я прикоснусь к ней. Использование OnTouchListener. Но я хочу, чтобы когда я отпускаю кнопку (ACTION_UP), она переходила в свою позицию перед этой операцией. Может ли кто-нибудь помочь мне, пожалуйста?
Мой код: (внутри при создании)
...
this.relative_layout.setOnTouchListener(new OnTouchListener()
{
@Override
public boolean onTouch(View view, MotionEvent event)
{
// TODO: Implement this method
if (event.getAction() == event.ACTION_MOVE)
{
float x = event.getX();
float y = event.getY();
my_button.setX(x);
my_button.setY(y);
} else if (event.getAction() == event.ACTION_UP)
/* here's the issue that I'm
* asking for help about
* What to do to return the button position back
* Like it was? */
return true;
}
});




Согласно документу, setX выполняет:
Sets the visual x position of this view, in pixels. This is equivalent to setting the translationX property to be the difference between the x value passed in and the current left property.
Чтобы изменить это, используйте setTranslationX(0);
То же самое для Y- setTranslationY(0);