検索フォームでフォーカスが当たったらある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