Problem with animation in Android Studio

0

I created a Float Buttom to start an animation, but when I click on it, the animation does not occur. I've done the debug to check the method that starts the animation and it happens normally. I think it might be some XML problem.

the animation XML:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/accelerate_decelerate_interpolator">

    <alpha
        android:fromAlpha="0.0"
        android:toAlpha="1.0"
        android:duration="2000" >
    </alpha>

</set>

The Listener of Float Buttom in Main Activity :

botaoAjuda.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Animation animation = AnimationUtils.loadAnimation(MainActivity.this,
                R.anim.tutorialanim);
        animation.start();
        Log.d("anim: ",animation+"");
    }
});

<android.support.design.widget.FloatingActionButton
    android:id="@+id/helpButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_margin="@dimen/fab_margin"
    android:foregroundGravity="bottom"
    app:fabSize="normal"
    app:layout_anchor="@+id/include"
    app:layout_anchorGravity="bottom|right" />

The include in Float Buttom :

<include
    layout="@layout/app_bar_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
    
asked by anonymous 13.06.2017 / 16:53

2 answers

2

Instead of:

animation.start();

You should use:

botaoAjuda.startAnimation(animation);

Note that you did not assign any animations to the button, simply created a variable of type Animation inside it.

    
13.06.2017 / 17:28
1

The problem is that your animation is not applied to any View , other than itself, which is not a view

When you create an animation via XML, your goal is to animate some view belonging to your layout, and this will not happen if you do not point your animation to any of them.

See :

Animation animation = AnimationUtils.loadAnimation(MainActivity.this,
            R.anim.tutorialanim);

ImageView mView = (ImageView) findViewById(R.id.view22);
mView.startAnimation(animation); // uma view qualquer definida no seu layout
    
13.06.2017 / 17:28