我为过渡设置了XML主题
<item name="android:windowContentTransitions">true</item>
<item name="android:windowActivityTransitions">true</item>
第一个活动中的代码:
Item clieckedItem = (Item) allResults.get(position); photo = clieckedItem.getImageUrl(); nameText = clieckedItem.getTitle();
if (photo != null) {
Picasso.with(MainActivity.this).load(photo).fit().into(mImageView);
}
mTextView.setText(nameText);
Pair[] pair = new Pair[2];
pair[0] = new Pair<View, String>(mImageView, "image_shared");
pair[1] = new Pair<View, String>(mTextView, "texview_shared");
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(this, pair);
Intent intent = new Intent(MainActivity.this, SharedElementActivity.class);
startActivity(intent, options.toBundle());
以及接收活动中
protected void onCreate(Bundle savedInstanceState) {
getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_shared_element);
并为我要共享的所有视图添加android:transitionName。
我错过了什么?