I was playing around with the fab in the support design library when I ran inti this issue. I replaced the onCreate method in the default Blank Activity template in Android Studio, this is what it looks like:
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.animation.TranslateAnimation;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
final FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
TranslateAnimation anim = new TranslateAnimation(0, -500, 0, -500);
anim.setDuration(1000);
anim.setFillEnabled(true);
anim.setFillAfter(true);
fab.startAnimation(anim);
}
});
fab.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
TranslateAnimation anim = new TranslateAnimation(0, -500, 0, -500);
anim.setDuration(1000);
anim.setFillEnabled(true);
anim.setFillAfter(true);
fab.startAnimation(anim);
return true;
}
});
}
}
So basically, I added an onClickListener and an onLongClickListener that translate the fab by 500idks, but the problem is that it doesn't work like it's supposed to.
When I click on it normally nothing happens, which is weird to start with. Here's a video of it happening.
When I longPress on it, it animates like I should, but only if I keep pressing, and whenever I lift my finger it goes back to the original position regardless of whether the animation is complete or not even though I set setFillEnabled(true)
and setFillAfter(true)
.
Here are videos of what happens when I lift my finger and when I leave my finger on the screen till the end and everything.
Why is this happening?