您好我使用此How to implement Custom listview text animation实现了添加到购物车动画。单击行项目时,TextView从列表行移动到底部角落到购物车图标。同样,我为图像实现了它,当从RecyclerView点击行项目时,图像开始移动到购物车中。
但在我的情况下购物车图标位于ActionBar 上,而我的RecyclerView位于ViewPager片段中。单击Recycler中的行项目时,图像将转换为ViewPager的选项卡布局(位于操作栏下方),但不会在操作栏上移动以触摸购物车图标。这是动画代码:
public void animateImage(String imageUrl, ImageView imageView) {
if (null == anim) {
anim = new ImageView(getActivity());
int targetX = 800;
int targetY = 0;
int[] screenLocation = new int[2];
imageView.getLocationOnScreen(screenLocation);
int x1 = screenLocation[0];
int y1 = screenLocation[1];
WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
layoutParams.width = 300;
layoutParams.height = 500;
getActivity().addContentView(anim, layoutParams);
Glide.with(getContext())
.load(imageUrl)
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
.fitCenter()
.into(anim);
anim.setTranslationX(x1);
anim.setTranslationY(y1);
anim.animate().scaleXBy(-0.5f).scaleYBy(-0.5f).setListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
}
@Override
public void onAnimationEnd(Animator animation) {
if (null != anim) {
anim.setVisibility(View.GONE);
}
anim = null;
}
@Override
public void onAnimationCancel(Animator animation) {
}
@Override
public void onAnimationRepeat(Animator animation) {
}
}).setDuration(400)
.translationX(targetX).translationY(targetY).start();
}
可能是什么问题?