web-dev-qa-db-ja.com

Activity / Fragment TransitionsはLollipop以前のデバイスと互換性がありますか?

Lollipop以前のデバイス(4.x)でShared Elementsを使用してアクティビティを移行しようとしています。出来ますか?これまでのところ、私はこれを試しています:

public class RewardDetail extends ActionBarActivity {
    @Override
    public void onCreate(final Bundle savedInstanceState) {
        ...

        ViewCompat.setTransitionName(imageView, TRANSITION_NAME);
    }

    ...

    public static void launch(ActionBarActivity activity, View transitionView, WelcomeReward detailData) {
        ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(activity, transitionView, TRANSITION_NAME);
        Intent intent = new Intent(activity, RewardDetail.class);
        intent.putExtra(PARAM_DATA, detailData);
        ActivityCompat.startActivity(activity, intent, options.toBundle());
    }
}

呼び出し元:

@Override
public void onClick(final View v) {
    int position = recyclerView.getChildPosition(v);
    WelcomeReward welcomeReward = data.get(position);
    RewardDetail.launch(WelcomeRewardActivity.this, v.findViewById(R.id.reward_view), welcomeReward);
}

ただし、「通常の」遷移(共有要素なし)になります。何か案は?

[〜#〜] edit [〜#〜]

このビデオによると、次のことが可能です。

https://www.youtube.com/watch?v=RhiPJByIMrM&index=8&list=WL

事前Lollipop用にこれを既に実装しているライブラリはありますか?

32
Cheborra

いいえ、Lollipop以前のデバイスではアクティビティ/フラグメントの移行はできません。 ドキュメント によると:

可能であれば、追加の起動情報を使用してアクティビティを開始します。

In Android 4.1+の追加オプションが導入され、アクティビティ起動アニメーションをより細かく制御できるようになりました。この機能が存在しない場合、アクティビティは通常どおり起動されます。

このStackOverflowの質問 に対するGeorge Mountの回答も参照してください。

18
Alex Lockwood

Lollipop以前のデバイスのアクティビティとフラグメントの移行については、このライブラリを確認できます

dependencies {
        compile 'com.albinmathew:PreLollipopTransition:1.1.2'
}

https://github.com/albinmathew/PreLollipopTransition

8
Albin Mathew

派手なLollipopアクティビティ/フラグメントのトランジションはLollipop以前では使用できませんが(サードパーティライブラリを使用しない場合)、アクティビティ間のトランジションに使用されるアニメーションをオーバーライドできます。

StartActivity()の呼び出しを開始する前後に、[Activity.overridePendingTransition]( http://developer.Android.com/reference/Android/app/Activity.htmlを呼び出すことができます。 #overridePendingTransition(int 、int))。アクティビティを離れるとき、同じメソッドを呼び出します。

同様に、ActivityOptionsCompatを使用して、移行中に使用するカスタムアニメーションを定義できます。

ActivityOptionsCompat opts =
    ActivityOptionsCompat.makeCustomAnimation(getActivity(), R.anim.in, R.anim.out);
startActivity(intent, opts.toBundle());
2
Dave Jensen

サポートライブラリはありますが、Android 5.0より前のバージョンでの(すべての)遷移をサポートしていません。ただし、いくつかの代替方法があります。

非公式の互換性ライブラリ
https://github.com/andkulikov/transitions-everywhere
https://github.com/takahirom/PreLollipopTransition
https://github.com/lgvalle/Material-Animations

Android KitKat
http://www.doubleencore.com/2013/11/new-transitions-framework/ およびSDKサンプルフォルダーにあるサンプル。

ここでこの質問の複製に以前に投稿しました: https://stackoverflow.com/a/27344471/1683141

2
Mdlc