我正在创建一个带有时间轴的Android应用。我使用ListView
来创建时间轴效果。当我点击ListViewItem
时,我使用makeSceneTransitionAnimation
来显示详细视图。一切正常,除非我在详细视图中并按下后退按钮,makeSceneTransitionAnimations
将页面设置为原始点击行上方的行,然后屏幕闪烁。
这是我用来创建动画的代码:
View timelineObject = view.findViewById(R.id.transition);
timelineObject.setTransitionName("selectClientTransition");
Intent intent = new Intent(this, DetailActivity.class);
ActivityOptionsCompat options = ActivityOptionsCompat.
makeSceneTransitionAnimation(this, timelineObject , "selectClientTransition");
this.startActivity(intent, options.toBundle());
我尝试在详细活动中覆盖后退按钮,但我没有看到将listview项目的位置作为参数传递给makeSceneTransitionAnimation
的方法。
答案 0 :(得分:0)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
Explode explode = new Explode();
getWindow().setExitTransition(explode);
}
super.onCreate(savedInstanceState);
/*------Your code When the list item is click------*/
Intent intent = new Intent(context1, Main_testcollapse.class);
intent.putExtra("time", list.get(pos).getTime());
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
ActivityOptions activityOptions = ActivityOptions.makeSceneTransitionAnimation((Activity) context1, view, "cardname");
startActivity(intent, activityOptions.toBundle());
} else {
startActivity(intent);
}
onCreate内的另一项活动
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().setAllowEnterTransitionOverlap(false);
Slide slide=new Slide(Gravity.END);
getWindow().setReturnTransition(slide);
}
答案 1 :(得分:-1)
您不需要处理反向操作,因为 makeSceneTransitionAnimation 方法本身就是这样做的。
对于您的情况,只需覆盖listview的onItemClick。
@Override public void onItemClick(AdapterView adapterView, View view, int position, long id) { Intent intent = new Intent(this, DetailActivity.class); ActivityOptionsCompat activityOptions = ActivityOptionsCompat.makeSceneTransitionAnimation( this, new Pair(view.findViewById(R.id.**id_of_your_list_view_item**), "detail:image"); ActivityCompat.startActivity(this, intent, activityOptions.toBundle()); }
id_of_your_list_view_item :动画从此ID开始,当用户点击后退按钮时,动画将回退到此ID。
DetailViewActivity onCreate方法将具有以下代码
ImageView mHeaderImageView = (ImageView) findViewById(R.id.imageview_header);
ViewCompat.setTransitionName(mHeaderImageView, "detail:image");
" detail:image" 是目标视图的标识