LoginSignup
11
12

More than 5 years have passed since last update.

Android addViewするときにフェードインなどのアニメーションを付けたいときの方法

Last updated at Posted at 2016-09-14

検索フォームでフォーカスが当たったらあるviewに入れ替えるってやつを

view.addView(otherView);

で実装していたんですが、ある日

フェードインで表示して欲しい

って要望が来たのでどうやればいいのかなって思って調べたんですが、やり方はいろいろあるっぽい。

パターン1 AnimationUtils

view.addView(otherView);
Animation animation = AnimationUtils.loadAnimation(getContext(), R.anim.fade_in);
otherView.startAnimation(animation);

パターン2 AlphaAnimation

view.addView(otherView);
// フェードアウトの場合はnew AlphaAnimation(1, 0);
AlphaAnimation animation = new AlphaAnimation(0, 1);
animation.setDuration(500);
otherView.startAnimation(animation);

パターン3 ObjectAnimator

view.addView(otherView);
otherView.setAlpha(0.0f);
ObjectAnimator animation = ObjectAnimator.ofFloat(otherView, "alpha", 1.0f);
animation.setStartDelay(500);
animation.start();

意外と簡単にできる!

参考URL

http://stackoverflow.com/questions/7432375/how-to-animate-an-adding-of-a-view-in-android
http://qiita.com/kazy/items/0ef55e1d750a49a9192f
http://cleanings.jp/develop/2807
http://blog.ch3cooh.jp/entry/20130122/1358846834

11
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
12