Search code examples
androiddictionarybuttonmovelag

Why does my buttons lag when they move?


Right now in my app, I have a main button. If you click on it, two more buttons appear and if you click on this main button again they disappear. I also made this two buttons move instead of just making them appear without animation. The problem here is that whenever they move, they lag.

This is the main method:

public void buttonClickAppear(View view) {
        animMove = loadAnimation(this, R.anim.anim_translate);
        if (!reportesState) {
            playas.startAnimation(animMove);
            playas.setVisibility(View.VISIBLE);
            res.startAnimation(animMove);
            res.setVisibility(View.VISIBLE);
            reportesState = true;
        } else {
            playas.setVisibility(View.GONE);
            res.setVisibility(View.GONE);
            reportesState = false;
        }
    }

This is the animation:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/linear_interpolator">
    <translate
        android:fromXDelta="100"
        android:toXDelta="100"
        android:duration="80"
        />

</set>

What should I do? What could the problem be? Maybe, the xml code for the animation is wrong, I dont know...


Solution

  • You don't need the android:toXDelta="100" line. It is causing the lag.

    <?xml version="1.0" encoding="utf-8"?>
    <set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/linear_interpolator">
        <translate
            android:duration="80"
            android:fromXDelta="100"/>
    </set>