LoginSignup
24
21

More than 5 years have passed since last update.

Androidアプリでボタンをフェードイン&フェードアウトさせる方法

Last updated at Posted at 2014-05-11

Androidアプリでボタンをフェードイン&フェードアウトさせる方法

ボタンをフェードインしたり、フェードアウトしたりする方法をメモ。
例としてイメージボタンでのフェードイン、フェードアウトを実装。

使いどころはあまりないかもしれないが、躍動感のあるアプリにしたい場合には使えるかも。。

■実装方法

①フェードインの実装方法

onCreateメソッド内等に以下を記述する。

//フェードイン対象のボタンを指定
ImageButton btn = (ImageButton)findViewById(R.id.btn);

//フェードインアニメーションの準備する(1,0)フェードアウト、(0,1)フェードイン
AlphaAnimation feedin_btn = new AlphaAnimation( 0, 1 );

//表示時間を指定
feedin_btn.setDuration( 50 );

//実行
btn.startAnimation( feedin_btn );

②フェードアウトの実装方法

onCreateメソッド内等に以下を記述する。

//フェードアウト対象のボタンを指定
ImageButton btn = (ImageButton)findViewById(R.id.btn);

//フェードインアニメーションの準備する(1,0)フェードアウト、(0,1)フェードイン
AlphaAnimation feedin_btn = new AlphaAnimation( 1, 0 );

//表示時間を指定
feedin_btn.setDuration( 50 );

//実行
btn.startAnimation( feedin_btn );

上記のフェードアウトとフェードインの違いは以下のところだけ。
イン :AlphaAnimation feedin_btn = new AlphaAnimation( 0, 1 );
アウト:AlphaAnimation feedin_btn = new AlphaAnimation( 1, 0 );

以上、参考まで。


簡単家計簿 Androidアプリ

音感診断 Androidアプリ

24
21
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
24
21