有活性/片段转换与pre-棒棒糖设备兼容?棒棒糖、活性、片段、设备

2023-09-12 07:22:47 作者:无人像我i

我试图让使用共享元素一个pre-棒棒糖装置(4.x版)上的活动转型。可能吗?到目前为止,我想这样的:

I'm trying to make an Activity Transition using Shared Elements on a pre-Lollipop device (4.x). Is it possible? So far, I'm trying this:

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);
}

但它会导致常规过渡(没有共享的元素)。任何想法?

But it results in a "regular" transition (no shared element). Any ideas?

修改

根据这段视频,它可以做:

According to this video, it could be done:

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

有没有已经在实施本作pre棒棒糖?库

Is there a library already implementing this for pre Lollipop ?

推荐答案

没有,活动/片段转换是不可能的pre-棒棒糖设备。按照文档:

No, Activity/Fragment Transitions are not possible on pre-Lollipop devices. According to the documentation:

开始用额外的启动信息的活动。

Start an activity with additional launch information, if able.

在安卓4.1+其他选项进行了介绍,以便在活动推出动画的更多控制。应用程序可以使用此方法与ActivityOptionsCompat可用时使用这些动画。当具备此功能不存在,该活动将正常启动了平台的版本上运行。

In Android 4.1+ additional options were introduced to allow for more control on activity launch animations. Applications can use this method along with ActivityOptionsCompat to use these animations when available. When run on versions of the platform where this feature does not exist the activity will be launched normally.

又见乔治山的回答这个计算器的问题。