Salut, j'ai écrit ce code dans le but qu'en cliquant sur button1 une animation se deplace en haut a gauche de l'ecran, sauf qu'au final elle sort a droite de l'ecran bien avant d'arriver en haut et je ne comprends pas pourquoi, quelqu'un voit ou est le problème ?

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
 
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Layout;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.LayoutAnimationController;
import android.widget.Button;
import android.widget.TextView;
import android.view.animation.*;
 
import java.util.Random;
 
 
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
 
    Button button1, button2, button3, button4;
    TextView textViewTest;
    Animation animation;
    AnimationSet set;
    float width, height, xTextViewTest, yTextViewTest;
    Random random;
    int[] locationTemp = new int[2];
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
 
        button1 = (Button) findViewById(R.id.Button1);
        button2 = (Button) findViewById(R.id.Button2);
        button3 = (Button) findViewById(R.id.Button3);
        button4 = (Button) findViewById(R.id.Button4);
 
        button1.setOnClickListener(this);
        button2.setOnClickListener(this);
        button3.setOnClickListener(this);
        button4.setOnClickListener(this);
 
        textViewTest = (TextView) findViewById(R.id.TextViewTest);
 
 
        set = new AnimationSet(true);
        set.setDuration(3000);
 
        DisplayMetrics metrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(metrics);
 
        height = (float) metrics.heightPixels;
        width = (float) metrics.widthPixels;
 
    }
 
    @Override
    public void onClick(View view) {
 
        textViewTest.getLocationOnScreen(locationTemp);
        xTextViewTest = (float) locationTemp[0];
        yTextViewTest = (float) locationTemp[1];
        switch (view.getId()) {
            case R.id.Button1:
                textViewTest.setText("1");
                animation = new TranslateAnimation(0f, width - xTextViewTest, 0f, yTextViewTest - height);
                break;
            case R.id.Button2:
                textViewTest.setText("2");
                break;
            case R.id.Button3:
                textViewTest.setText("3");
                break;
            case R.id.Button4:
                textViewTest.setText("4");
                break;
        }
        set.addAnimation(animation);
        textViewTest.startAnimation(set);
 
    }
}