我想显示活动转换效果,如链接http://blog.stylingandroid.com/material-part-8/意味着点击listview项目活动从中间打开并慢慢增加上下方。
我做了以下代码,但是它显示了其他过渡效果。根据上面的链接,它没有像预期的那样工作。
在FirstActivty.java中
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(FirstActivity.this, SecondActivity.class);
String transitionName = getString(R.string.transition);
ActivityOptionsCompat transitionActivityOptions = ActivityOptionsCompat.makeSceneTransitionAnimation(FirstActivity.this, view, transitionName);
ActivityCompat.startActivity(FirstActivity.this, intent, transitionActivityOptions.toBundle());
}
});
在SecondActivity.java中
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
getActionBar().setDisplayHomeAsUpEnabled(true);
RelativeLayout rootElement = (RelativeLayout) findViewById(R.id.root);
//Set Transition
ViewCompat.setTransitionName(rootElement,getString(R.string.transition));
}
@Override
public boolean onOptionsItemSelected(MenuItem menuItem) {
int id = menuItem.getItemId();
if (id == android.R.id.home) {
//Finish Transition
ActivityCompat.finishAfterTransition(this);
return true;
}
return super.onOptionsItemSelected(menuItem);
}