I've implemented a small animation on a button placed over a list view.
Basically it's like a quick action button
to add/refresh the list.
What I want to do is to animate the button once the user has clicked on it and display a popup
. Once the popup
has been dismissed, the button should go back to its initial state.
I've made the followning code:
final PopupWindow popup = new PopupWindow(getContext());
// Attach layout
LayoutInflater layoutInflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = layoutInflater.inflate(R.layout.core_popup_quickactions, new LinearLayout(getContext()));
// Creating the PopupWindow
popup.setContentView(layout);
popup.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
popup.setWidth(WindowManager.LayoutParams.WRAP_CONTENT);
popup.setOutsideTouchable(true);
popup.setFocusable(true);
popup.setBackgroundDrawable(new BitmapDrawable());
popup.setOnDismissListener(new OnDismissListener() {
@Override
public void onDismiss()
{
// Rotate back
RotateAnimation animation = new RotateAnimation(-45.0f, 0.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
animation.setDuration(300);
animation.setRepeatCount(0);
animation.setFillAfter(true);
animation.setFillBefore(true);
animation.setFillEnabled(true);
startAnimation(animation);
animation.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation arg0)
{
QuickActionButton.this.setClickable(false);
}
@Override
public void onAnimationEnd(Animation arg0)
{
QuickActionButton.this.setClickable(true);
}
@Override
public void onAnimationRepeat(Animation arg0)
{
}
});
}
});
popup.setTouchable(false);
popup.showAsDropDown(this, 0, -dpToPx(350));
// Rotate the icon
RotateAnimation animation = new RotateAnimation(0.0f, -45.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
animation.setDuration(300);
animation.setRepeatCount(0);
animation.setFillAfter(true);
animation.setFillBefore(true);
animation.setFillEnabled(true);
startAnimation(animation);
animation.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation arg0)
{
popup.setTouchable(false);
}
@Override
public void onAnimationEnd(Animation arg0)
{
popup.setTouchable(true);
}
@Override
public void onAnimationRepeat(Animation arg0)
{
}
});
The problem now is that when I scroll the view and press the quick action button
, the animation starts and is reseted after a few miliseconds.
Is that a normal behaviour because of the Popup
?