Android-fragment-transitions
Android-フラグメントの移行
移行とは何ですか?
Lollipopのアクティビティとフラグメントのトランジションは、トランジションと呼ばれるAndroidの比較的新しい機能の上に構築されています。 KitKatで導入された移行フレームワークは、アプリケーション内の異なるUI状態をアニメーション化するための便利なAPIを提供します。 このフレームワークは、シーンとトランジションという2つの重要な概念に基づいて構築されています。 シーンはアプリケーションのUIの特定の状態を定義し、トランジションは2つのシーン間のアニメーション化された変更を定義します。
シーンが変化すると、トランジションには2つの主な責任があります-
- 開始シーンと終了シーンの両方で各ビューの状態をキャプチャします。
- あるシーンから別のシーンへのビューをアニメーション化する違いに基づいて、アニメーターを作成します。
例
この例では、フラグメント遷移を使用してカスタムアニメーションを作成する方法を説明します。 それでは、Hello World Exampleの作成中に行った手順と同様に、次の手順に従ってみましょう-
Step | Description |
---|---|
1 | You will use Android Studio to create an Android application and name it as fragmentcustomanimations under a package com.example.fragmentcustomanimations, with blank Activity. |
2 | Modify the activity_main.xml, which has placed at res/layout/activity_main.xml to add a Text View |
3 | Create a layout called fragment_stack.xml.xml under the directory res/layout to define your fragment tag and button tag |
4 | Create a folder, which is placed at res/ and name it as animation and add fragment_slide_right_enter.xml fragment_slide_left_exit.xml, ,fragment_slide_right_exit.xml and fragment_slide_left_enter.xml |
5 | In MainActivity.java, need to add fragment stack, fragment manager, and onCreateView() |
6 | Run the application to launch Android emulator and verify the result of the changes done in the application. |
以下は_res.layout/activity_main.xml_のコンテンツになり、TextViewが含まれます。
以下は res/animation/fragment_stack.xml ファイルの内容です。 フレームレイアウトとボタンが含まれていた
以下は res/animation/fragment_slide_left_enter.xml ファイルの内容です。 setメソッドとオブジェクトアニメーターが含まれていた
以下は、 res/animation/fragment_slide_left_exit.xml file.itのコンテンツであり、セットおよびオブジェクトアニメータータグが含まれています。
次のコードは、* res/animation/fragment_slide_right_enter.xml * file.itのコンテンツであり、セットおよびオブジェクトアニメータータグが含まれています。
次のコードは* res/animation/fragment_slide_right_exit.xml * fileのコンテンツになり、セットおよびオブジェクトアニメータータグが含まれます
次のコードは src/main/java/MainActivity.java ファイルのコンテンツになります。 ボタンリスナー、スタックフラグメント、onCreateViewが含まれていた
以下は AndroidManifest.xml のコンテンツになります
アプリケーションを実行する
作成した Fragment Transitions アプリケーションを実行してみましょう。 環境のセットアップ中に AVD を作成したと思います。 Android Studioからアプリを実行するには、プロジェクトのアクティビティファイルの1つを開き、ツールバーの[画像を実行:/android/images/eclipse_run.jpg [Eclipse Run Icon]アイコンをクリックします。 AndroidはアプリをAVDにインストールして起動し、セットアップとアプリケーションで問題がなければ、次のエミュレータウィンドウが表示されます。
新しいフラグメントをクリックすると、以下に示すように、最初のフラグメントが2番目のフラグメントに変更されます