android - 用android :rotation xml旋转一个按钮

标签 android

我想要一个按钮(作为图像)顺时针旋转仅用于 UI。我不想旋转按钮 onClick。只需在 xml 文件中旋转就足够了。 android:rotation 对我不起作用。

我的代码是

<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="New Button" android:background="@drawable/button" android:rotation="-90" android:id="@+id/button" android:layout_gravity="right|left" android:layout_centerVertical="true" android:layout_centerHorizontal="true" />

最佳答案

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate android:fromDegrees="0"
    android:toDegrees="360"
    android:pivotX="50%"
    android:pivotY="50%"
    android:duration="600"
    android:repeatMode="restart"
    android:repeatCount="infinite"
    android:interpolator="@android:anim/cycle_interpolator"/>

</set>

顺时针——使用正 toDegrees 值

逆时针方向——使用负的 toDegrees 值

关于android - 用android :rotation xml旋转一个按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27728363/

相关文章:

java - 如何在安卓上隐藏公钥?

java - 导致应用程序崩溃的未知错误

android - CardView 海拔不适用于 Android 5.1.1

安卓 map : difference between OnMapReady() and OnMapLoaded()

java - 为什么 RGBA 位图需要 3x3 数组来存储 1 个像素,如何避免这种情况?

android - 我怎样才能在 react-native android 中找到 ViewById()

android - 更新到 New Android Studio 3.2 后出现错误

android - 检查房间中是否已存在对象

android - 消除过多的 if 和 else 语句

android - 如何从 Jetpack Compose TextField 关闭虚拟键盘?