【发布时间】:2021-02-20 11:37:40
【问题描述】:
我有一个 ImageView 和 Button。按钮视图位于屏幕底部。 ImageView 位于按钮上方。当我单击按钮时,图像应移动到屏幕中心。移动到中心后,单击图像应该旋转。但在我的情况下,它在更宽的圆圈中旋转,而不是在中心旋转。
我正在使用下面的代码。
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:scaleType="centerCrop"
android:visibility="visible" />
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Start" />
点击按钮后,移动到屏幕中心
image.animate().y(metrics.heightPixels / 2 - image.getHeight() / 2).x(metrics.widthPixels / 2 - image.getWidth() / 2)
在上述步骤后旋转图像。
RotateAnimation animRotate = new RotateAnimation(0.0f, 360.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
animRotate.setDuration(duration);
animRotate.setInterpolator(new DecelerateInterpolator(1.5f));
image.startAnimation(animRotate)
它不是在中心旋转,而是像更宽的圆圈一样旋转。你能帮忙吗?
【问题讨论】:
标签: java android android-layout animation