【问题标题】:rotate an image and translate it using xml旋转图像并使用 xml 进行翻译
【发布时间】:2020-04-16 22:32:11
【问题描述】:
我需要这个练习的帮助。我需要在 xml 文件中插入图像,它必须在前两秒旋转,最后必须平移 100,最后图像必须保持在最终位置。
在 activity_main.xml 我正在尝试这样:
<ImageView
android:id="@+id/imageView"
android:rotation="90"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/vEPxtF9" />
这只会旋转图像。
是否可以只使用没有 java 的 xml 文件来做到这一点?
【问题讨论】:
标签:
android
xml
imageview
【解决方案1】:
希望这对你来说已经足够好了(有点“只是通过 xml”)
您可以在您的View 上使用RotateAnimation。
这是rotation.xml
<?xml version="1.0" encoding="utf-8"?>
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="90"
android:toDegrees="100"
android:pivotX="50%"
android:pivotY="50%"
android:duration="2000"/>
然后把这个动画交给你的View:
Animation rotation = AnimationUtils.loadAnimation(this, R.anim.rotation);
myView.startAnimation(rotation);