TextView Выезжает за границы экрана при анимации и как реверсировать движение когда Textview достигает границы
Вот мой xml файл
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/constraintlay"
android:clipChildren="false"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/rel"
>
<TextView
android:clipChildren="false"
android:id="@+id/movingText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="false"
android:layout_alignParentTop="false"
android:layout_alignParentEnd="false"
android:layout_alignParentBottom="false"
android:gravity="center"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:onClick="stopAction"
android:text="HELLO"
android:textSize="17sp" />
</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
И вот сам java код
@Override
public boolean onTouchEvent(MotionEvent event)
{
float x = event.getRawX();
float y = event.getRawY();
}
if((int)x>(height/2)-200) {
Log.e("Up","Going up");
textView.animate().yBy(1000).setDuration(5000).setStartDelay(10);
} else if ((int)x<(height/2)-200) {
Log.e("Down","Going down");
textView.animate().yBy(-1000).setDuration(5000).setStartDelay(10);
}
Как можно заметить, на первом скрине надпись еще не достигла границы, а на втором уже прошла ее. Как можно это исправить и реверсировать движение при касании границы ?

