[Android] AnimationSet アニメーションの組み合わせ

android.view.animation.Animationのクラスを使って、alpha, rotate, scale, translate のアニメーション効果を出せますが、これらを組み合わせたアニメーションをAnimationSetで作ることもできます。
 
1x1.trans - [Android] AnimationSet アニメーションの組み合わせ


Android Studio
2021.2.1




AnimationSet

 
Viewにアニメーションを施したいときはこのAnimationが簡単です。ただし途中で止めるなど込み入ったことはできません。Property Animation 等を使いましょう。
 
設定方法は2通りあります。
 

 

XML attributes

 
res以下にanimというフォルダーを作成してxmlファイルを置きます。

animationの属性設定は<set />タグを使って以下のように設定します。今回はscaleとrotateを組み合わせてみます。

res\anim\animation_set.xml


 
scale: viewの大きさを2秒かけて0にします。縮小はviewの中央座標で実行
rotate: 0から120まで2秒かけて回転させます。回転軸はparentの(0%, 50%)を中心に回転させます。
 

MainActivity.java


 
activity_main.xml


 
strings.xml

 

コードで記述

 
AnimationSetのConstructorの1つです。


boolean shareInterpolator:補間処理を共有(true)するか個別(false)にするかの選択
addAnimation(Animation a):rotateやscaleのアニメーションをsetに使いしていきます
 
MainActivity.java


 
レイアウト
activity_main.xml


 
strings.xml

 

サンプル動画

 

 
 
関連ページ:

 
References:
AnimationSet
Animation Resources

シェアする

  • このエントリーをはてなブックマークに追加

フォローする