我正在尝试在 Lollipop 之前的设备 (4.x) 上使用共享元素进行 Activity 转换。可能吗?到目前为止,我正在尝试这个:
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);
}
但它会导致“常规”过渡(没有共享元素)。有什么想法吗?
编辑
根据这个视频,可以做到:
https://www.youtube.com/watch?v=RhiPJByIMrM&index=8&list=WL
是否有一个库已经为 pre Lollipop 实现了这个?
最佳答案
不, Activity/fragment 转换在 Lollipop 之前的设备上是不可能的。根据documentation :
Start an activity with additional launch information, if able.
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.
另见 George Mount 对 this StackOverflow question 的回答.
关于java - Activity/fragment 转换是否与 Lollipop 之前的设备兼容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26567377/