FragmentをAnimationさせて遷移する方法です。

フラグメントの画面遷移する際に右から左へアニメーションしています。

javaファイルから見て行きます。

画面遷移をする際にreplace関数を使ってfragmentを切り替えていますが、
replaceの前に、setCustomAnimations関数を呼んで、アニメーションを設定したAnimファイルをセットしてあげればOKです。

setCustomAnimations

added in API level 13

Set specific animation resources to run for the fragments that are entering and exiting in this transaction. The popEnter and popExit animations will be played for enter/exit operations specifically when popping the back stack.

Parameters
enter int
exit int
popEnter int
popExit int
Returns
FragmentTransaction

今回Fragmentを切り替える際にAddBackStackし、戻るボタンを押した際もアニメーションをさせたいので、
第3,4引数のあるsetCustomAnimations関数を呼んでいます。

では、animationファイルを見ていきます。

Translateの要素については公式ドキュメントでチェックしてください