Basically i have a TextView which needs to move from right side to the other (I am testing something for a different project).Instead, everything is still. Nothing is executed.
Another thing to point out: If I remove the if statement, which is necessary in my case, everything works just fine. I thought the condition is false, so I put an else statement. Same thing happened - nothing. I tested whether or not the condition is false - it was true. So the code inside the if statement should've been executed.
Everything seems logical to me, but I could be wrong. Could you help me? What could I change? Do you have a different approach to my problem? Thanks!
P.S: The problem is not animating the TextView. The problem is the time delay.
XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:background="#000000"
android:text="0"
android:textColor="#000000" />
</RelativeLayout>
Java:
package com.nicksoft.test;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.os.Handler;
import android.widget.TableLayout;
import android.widget.TextView;
import android.widget.Toast;
import java.util.concurrent.TimeUnit;
public class MainActivity extends AppCompatActivity {
int ind = -1;
private Handler h = new Handler();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
r.run();
}
private Runnable r = new Runnable() {
@Override
public void run() {
if(findViewById(R.id.textView).getX()>0) {
findViewById(R.id.textView).setTranslationX(ind);
ind--;
h.postDelayed(r,5);
}
}
};
}