Help us understand the problem. What is going on with this article?

【Kotlin】AndroidでiOSライクな画面遷移アニメーションを実装する

簡単に言えばiOSでUINavigationControllershowするような画面遷移を、
Androidで簡単に実装出来ます。

手順1:res/animを作成する

スクリーンショット 2020-09-10 11.39.28.png

手順2:画像のようにxmlファイルを4件追加する

close_enter.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate android:fromXDelta="-100%"
        android:toXDelta="0%"
        android:duration="300"
        android:fillAfter="true"
        android:fillEnabled="true"/>
</set>

close_exit.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate android:fromXDelta="0%"
        android:toXDelta="100%"
        android:duration="300"
        android:fillAfter="true"
        android:fillEnabled="true"/>
</set>

open_enter.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate android:fromXDelta="100%"
        android:toXDelta="0%"
        android:duration="300"
        android:fillAfter="true"
        android:fillEnabled="true"/>
</set>

open_exit.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate android:fromXDelta="0%"
        android:toXDelta="-100%"
        android:duration="300"
        android:fillAfter="true"
        android:fillEnabled="true"/>
</set>

手順3:アニメーションを行いたいA画面の画面遷移実行時に下記の記述を入れる。

val intent = Intent(this, MainActivity::class.java)
startActivity(intent)
overridePendingTransition(R.anim.open_enter, R.anim.open_exit);

手順3:閉じるアニメーションを行いたいB画面の画面遷移実行時に下記の記述を入れる。

    override fun finish() {
        super.finish()
        overridePendingTransition(R.anim.close_enter, R.anim.close_exit);
    }
godaikun_method
「そうだよ、だからこそ現実にしたいんじゃない。本当は綺麗事が一番いいんだもん。これ(マウント)でしかやり取りできないなんて、悲しすぎるから。」
https://twitter.com/godaikun_method
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした