Android 動畫 Animation
阿新 • • 發佈:2019-02-09
MainActivity
public class MainActivity extends AppCompatActivity { ImageView imageView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); imageView = (ImageView)findViewById(R.id.img); Animation animation = AnimationUtils.loadAnimation(this,R.anim.main_set_in); imageView.setAnimation(animation); } }
anim/main_set_in.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" > <rotate android:duration="3000" android:fromDegrees="0" android:toDegrees="+360" android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:pivotX="50%" android:pivotY="50%" /> <!-- rotate 旋轉動畫效果 屬性:interpolator 指定一個動畫的插入器 在我試驗過程中,使用android.res.anim中的資源時候發現 有三種動畫插入器: accelerate_decelerate_interpolator 加速-減速 動畫插入器 accelerate_interpolator 加速-動畫插入器 decelerate_interpolator 減速- 動畫插入器 其他的屬於特定的動畫效果 浮點數型值: fromDegrees 屬性為動畫起始時物件的角度 toDegrees 屬性為動畫結束時物件旋轉的角度 可以大於360度 說明: 當角度為負數——表示逆時針旋轉 當角度為正數——表示順時針旋轉 (負數from——to正數:順時針旋轉) (負數from——to負數:逆時針旋轉) (正數from——to正數:順時針旋轉) (正數from——to負數:逆時針旋轉) pivotX 屬性為動畫相對於物件的X座標的開始位置 pivotY 屬性為動畫相對於物件的Y座標的開始位置 說明: 以上兩個屬性值 從0%-100%中取值 50%為物件的X或Y方向座標上的中點位置 長整型值: duration 屬性為動畫持續時間 說明: 時間以毫秒為單位 --> </set>