今天在項目中遇到了一個需求就是將TextView旋轉45度
動畫可以在xml中定義也可以在代碼中定義個人比較喜歡使用xml所以這裏我用的就是xml
首先在res中建立一個anim文件夾名字可以隨便起這裏我直接上代碼
文件目錄res/anim/rotate_text.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate android:fromDegrees="0"
android:toDegrees="-45"
android:pivotX="0"
android:pivotY="100%"
/>
<!--rotate爲旋轉動畫還有其他幾個動畫我這裏就不寫了-->
<!--android:fromDegrees="0" 初始角度-->
<!-- android:toDegrees="-45" 結束角度-->
<!-- android:pivotX="0" 和 android:pivotY="0" 代表旋轉軸點xy座標-->
</set>
然後在代碼中的使用
//個人理解獲取動畫
Animation animation = AnimationUtils.loadAnimation(context, R.anim.trogin_text);
//動畫結束後是否保留動畫在當前位置
animation.setFillAfter(true);
TextView tv = new TextView(this);
//給當前組件設置動畫
tv.setAnimation(animation);
好了今天的動畫就是這些 其他幾個補間動畫的使用方法和旋轉動畫的用法相同