【发布时间】:2018-05-23 09:27:11
【问题描述】:
所以我的问题是我想在双击 RecyclerView 适配器中的项目后触发 ImageView 上的动画。我检测到适配器中的双击,以int[] location的格式获取点击区域的坐标,调用Fragment中的方法传递位置。
public void performAnimation(int[] location) {
ImageView imageView = new ImageView(getContext());
imageView.setImageDrawable(getActivity().getDrawable(R.drawable.ic_imageview));
ConstraintLayout.LayoutParams params =
new ConstraintLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.setMargins(0, location[0], 0, location[1]);
imageView.setLayoutParams(params);
parentViewGroup2.addView(imageView);
ObjectAnimator translateAnim = ObjectAnimator.ofFloat(imageView, View.TRANSLATION_Y, 0.5f);
translateAnim.setDuration(2000);
translateAnim.start();
所以问题是我只能在布局中绘制图像,但动画不会开始。我也尝试过使用带有 beginDelayedTransition 的 TransitionManager,但同样没有。有谁知道我做错了什么?提前致谢。
【问题讨论】:
标签: android android-layout android-fragments android-animation