我在放置在列表视图上的按钮上实现了一个小动画。基本上它就像quick action button
添加/刷新列表。
我想要做的是在用户单击按钮后为按钮设置动画并显示popup
. popup
关闭后,按钮应返回其初始状态。
我制作了以下代码:
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)
{
}
});
现在的问题是,当我滚动视图并按下 时quick action button
,动画开始并在几毫秒后重置。
这是正常的行为Popup
吗?