我正在使用 Master/Detail 模式,目前正在转向 Android Lollipop。如果我单击 ListView 中的一个项目,我希望有一个新的活动转换。动画正在运行,但我不知道如何在共享元素(在我的情况下为 ImageView)之间制作特定动画。
如果我单击自定义 ListView 中的一行(带有图像和文本),则转换应切换到 DetailActivtiy 中的图像。它应该类似于此视频:http: //youtu.be/RhiPJByIMrM?t= 2m41s或此视频:http: //youtu.be/XkWI1FKKrs4
我已经将此代码添加到我的两个 ImageViews 中:
<ImageView
android:transitionName="@string/transition_title_image"/>
我的列表活动:
@Override
protected void onCreate(Bundle savedInstanceState) {
if (Build.VERSION.SDK_INT >= 21) {
//To enable window content transitions in your code instead, call the Window.requestFeature() method:
getWindow().requestFeature(android.view.Window.FEATURE_CONTENT_TRANSITIONS);
Transition ts_enter = new Slide(); //Slide(); //Explode();
Transition ts_exit = new Explode();
ts_enter.setDuration(2000);
ts_exit.setDuration(2000);
/*
If you have set an enter transition for the second activity,
the transition is also activated when the activity starts.
*/
getWindow().setEnterTransition(ts_enter);
getWindow().setExitTransition(ts_exit);
}
super.onCreate(savedInstanceState);
使用此方法调用我的 DetailActivity:
if (Build.VERSION.SDK_INT >= 21) {
Intent intent = new Intent(ArticleListActivity.this, ArticleDetailActivity.class);
intent.putExtra("pos", id);
intent.putExtra("articleList", articleList);
String transitionName = getString(R.string.transition_title_image);
ImageView article_thumb = (ImageView) findViewById(R.id.article_thumb);
ActivityOptionsCompat options =
ActivityOptionsCompat.makeSceneTransitionAnimation(ArticleListActivity.this,
article_thumb, // The view which starts the transition
transitionName // The transitionName of the view we’re transitioning to
);
ActivityCompat.startActivity(ArticleListActivity.this, intent, options.toBundle());
}
我的详细活动:
@Override
protected void onCreate(Bundle savedInstanceState) {
if (Build.VERSION.SDK_INT >= 21) {
//To enable window content transitions in your code instead, call the Window.requestFeature() method:
getWindow().requestFeature(android.view.Window.FEATURE_CONTENT_TRANSITIONS);
Transition ts_enter = new Slide(); //Slide(); //Explode();
Transition ts_exit = new Explode(); //Slide(); //Explode();
ts_enter.setDuration(2000);
ts_exit.setDuration(2000);
getWindow().setEnterTransition(ts_enter);
getWindow().setExitTransition(ts_exit);
}
super.onCreate(savedInstanceState)
;